[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

using my template class

From: ArbolOne
Subject: using my template class
Date: Fri, 28 Sep 2012 18:23:12 -0700 (PDT)
User-agent: G2/1.0

template <class T, const int> class Data {
    T data;
    int id;
    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 
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. 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]