Thread: trying to learn class templates what am i doing wrong

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    14

    trying to learn class templates what am i doing wrong

    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    #include <iomanip>
    
    
    using namespace std;
    const int CAPACITY = 5;
    
    template <class T>
    
    class A
    {
            public:
                      A();  
                    ~A();  
        
            private:
            T num;
            
    };
    
    template<class T>
    
     A<T>::A()
    
    {
    
        cout << "Constructor started"<<endl;
    
    }
    
    int main(){
    
        A<int> object;
        system("pause");
    }
    just want to start the constructor but i get an error message
    Error 2 error LNK1120: 1 unresolved externals

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    The unresolved external will be because you have not defined the destructor.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help me learn what im doing wrong
    By Die The Villain in forum C Programming
    Replies: 6
    Last Post: 04-08-2011, 11:01 PM
  2. Class templates
    By SterlingM in forum C++ Programming
    Replies: 1
    Last Post: 01-09-2010, 09:11 PM
  3. New to class templates
    By lisa1901 in forum C++ Programming
    Replies: 10
    Last Post: 10-02-2007, 04:23 PM
  4. class templates...
    By Anddos in forum C++ Programming
    Replies: 1
    Last Post: 03-17-2006, 09:30 PM
  5. class templates
    By tygernoot in forum C++ Programming
    Replies: 2
    Last Post: 11-21-2004, 10:26 AM