trying to learn class templates what am i doing wrong

This is a discussion on trying to learn class templates what am i doing wrong within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream> #include <fstream> #include <string> #include <iomanip> using namespace std; const int CAPACITY = 5; template <class T> ...

  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,531
    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 in reply to you, it is likely you deserve it. Suck it up, sunshine, 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-09-2011, 12:01 AM
  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, 05: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21