Advertisement

Template error

Started by March 25, 2002 12:41 AM
1 comment, last by Jeff D 22 years, 9 months ago
I''m running into an error with my templated class. For learning experience I want to try to make a little programming language with C++. So one of the things that struct me that could be hard would be variables. I figured I could make a template class to save the name and the data in a vector. The class is like this:
  

template< class T > class CData
{

   public:
      CData(){};
      ~CData(){};
      void SetData( string name, T data)
      {

          Data = data;
          Name = Name;

      }
      void GetData() const{return Data;}     

   private:
      string Name;
      T      Data;

};

vector< CData< int > > IntUserData;

CData< int > NewData;
NewData.SetData("MyVariable", 25);
IntUserData.push_back(NewData);
cout << IntUserData[1].GetData; // error here

  
I get this error: No overloaded << operator Or something like that. If you can help, I know someone can , I thank in advance. Jeff D
Suffered seven plagues, but refused to let the slaves go free. ~ Ross Atherton
For one thing, GetData returns void. It should return T or something similar.

Also, you need parens in your output statement: GetData().

And SetData should be
     void SetData( string name, const T& data) 

To avoid unnecessary copies.
---visit #directxdev on afternet <- not just for directx, despite the name
Advertisement
Thanks man I changes everything you told me to do and it works now. I honestly cant believe I didn''t see that. The parans after GetData was a typo here tho.

Again thx.

Jeff D
Suffered seven plagues, but refused to let the slaves go free. ~ Ross Atherton

This topic is closed to new replies.

Advertisement