![]() |
| ||
| Class Template Problem - Constructor Issues - Please help Hey guys, new poster here. I'm rather desperate here, I just do not understand the concept of templates very well. I've used the search function, but I don't see the problem addressed in any other threads. Any help is much appreciated. My assignment is to create a templated vector class using the following prototypes/definitions: //I cannot modify these prototypes at all. #ifndef _MYVECTOR I think I understand how to do it, and have written all the functions, but it will not compile, and I think my constructor, copy constructor, and destructor are the primary culprits, since they do not have a bracketed <T> as part of the function header. Here are the functions I've written: myVector::myVector() I get a compile error on the line of the constructor telling me that I can't use the template class myVector without template parameters. This makes sense, but I don't know how to fix it. Any help is appreciated. Thanks. |
| ||
| Re: Class Template Problem - Constructor Issues - Please help If you define a member function for a template class outside of the class definition, you need to recreate the template parameters: template <typename T> |
| ||
| Re: Class Template Problem - Constructor Issues - Please help 1 Attachment(s) Thanks, Narue, that was helpful. That solved most of my problems, and I figured out some of the exception handling issues that I had as well. I think something is still fundamentally wrong, as I am getting the following errors.
I get the following errors: Attachment 5604 What it refers to as line 127 is line 118 in what I've pasted here, and what it refers to as line 256 is line 247 here. The line it is referring to in the driver is: for(int i = 0; i < 10; i++) Please advise. Thanks again. I really have no idea what those errors mean. |
| ||
| Re: Class Template Problem - Constructor Issues - Please help what it actually does. Let me tell you what it actually does, and what it should do first what it does template <class T> basically T refers to int in your case now the new code becomes. void myVector<int>::grow(){ lets move from bottom up manner you'll recognise yourself.what does your sentence data[i] = temp.data[i] means ??? int is a primitive type not a aggregate type, so a compile error is there. now you know what should be change. |
| ||
| Re: Class Template Problem - Constructor Issues - Please help Yeah, I found that last night, thanks. temp is a pointer, not an object, so I just needed to change temp.data[i] to temp [i] and it worked. I have some sort of small logic error with popback and popfront, but everything else works fine. Thanks for your help. |
| ||
| Re: Class Template Problem - Constructor Issues - Please help Figured out my last logic error. Solved. Thanks! |
| All times are GMT -4. The time now is 9:11 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC