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
Template error
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:
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
To avoid unnecessary copies.
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement