By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,988 Members | 1,049 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,988 IT Pros & Developers. It's quick & easy.

copy constructors for template classes

P: 65
what is the difference between this two versions of copy constructors:

myClass(const myClass & mc);
myClass(const myClass<T> & mc);

here is the template class declaration:

Expand|Select|Wrap|Line Numbers
  1. template<class T>
  2. class myClass {
  3. private:
  4.         T val;
  5. public:
  6.         myClass(T v=0);  // default constructor
  7.         //myClass(const myClass & mc);  //copy constructor version1
  8.         myClass(const myClass<T> & mc);  //copy constructor  version2
  9.         void display() { cout<<"val: "<<val<<endl; }
  10. };
Jun 21 '07 #1
Share this Question
Share on Google+
1 Reply

P: 18
There isn't.

Inside a class you can use both className<T> or className. There's synomym.

Template is very powerful. What you can also do is something like:

template <class T1>
class c
c( c<T2> const & ); //you can copy c<int> into c<long> for example.

Jun 21 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.