|
-
October 18th, 2011, 12:29 PM
#12
Re: Help needed with class BookType
 Originally Posted by owllie
is it possible to provide me with an example code for the class template for my case??
Well as I stated previously, what you want is not just a couple of lines of code here and there. Writing C++ classes properly is an entire concept that needs to be learned.
can you list the copy constructor and the assignment constructor??
Assignment operators and copy constructor:
Code:
BookInfo(const BookInfo& ); // copy constructor
BookInfo& operator=(const BookInfo& ); // assignment operator
Those are assignment operators and copy constructor for a class called BookInfo. Just for now, create these two functions, but do not implement them. Also, make them private in your template class. This would at least prevent copying and assigning. If you attempt to copy or assign, you will get a compiler or linker error.
If you did not implement these functions as stated above, then your program will just blow up as soon as you assign one vector to another, pass or return a vector by value, etc. That's why we declare these functions but do not implement them, so that the compiler will flag us down for any copy/assignment usage we may have inadvertantly done.
More issues with your code:
First, "class" is not spelled with a capital 'C'.
Second, it makes no sense creating a template class called "BookInfo". It should be called MyVector, or DynArray, or something that denotes the data structure.
Regards,
Paul McKenzie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|