Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

using my template class

9 views
Skip to first unread message

ArbolOne

unread,
Sep 28, 2012, 9:23:12 PM9/28/12
to
template <class T, const int> class Data {
private:
T data;
int id;
public:
Data();
Data(T, const int);
virtual ~Data();
};
template <class T, const int x>
Data<T, x>::Data() {}

template <class T, const int x>
Data<T, x>::Data(T _data, const int _id) {
this->data = _data;
this->id = _id;
}
template <class T, const int x>
Data<T, x>::~Data() {}

template <class T, const int x>
Data<T, x>::Data(const Data& other) {
//copy ctor
}

int main(){
jme::Data <std::string, const int> d("data", 1);
std::cout << "Hello world!" << std::endl;
return 0;
}


The class above compiles, but when trying to use it in the main() function, I get this error:

-------------- Build: Debug in data ---------------

Compiling: main.cpp
C:\...\main.cpp: In function 'int main()':
C:\...\main.cpp:8: error: type/value mismatch at argument 2 in template parameter list for 'template<class T, int <anonymous> > class jme::Data'
C:\...\main.cpp:8: error: expected a constant of type 'int', got 'const int'
C:\...\main.cpp:8: error: invalid type in declaration before '(' token
C:\...\main.cpp:8: error: initializer expression list treated as compound expression
C:\...\main.cpp:8: warning: left-hand operand of comma has no effect
C:\...\main.cpp:8: warning: unused variable 'd'
Process terminated with status 1 (0 minutes, 0 seconds)
4 errors, 2 warnings

I am bit confused as to how to use a class like that.
0 new messages