tags:

views:

178

answers:

3

Hello, I've some problem with using templates:

myclass.h

#ifndef MYCLASS_H
#define MYCLASS_H

class myclass
{

private:


public:

    ~myclass();
     myclass();
    template<class S>
    void login(S login, S pass);
};



#endif // MYCLASS_H

myclass.cpp

#include "myclass.h"
#include "../additional_func.h" // for connect(QString,QString) function


myclass::myclass()
{

}

template <typename S>
void myclass::login(S login, S pass)
{

    additional_func->connect(login,pass);

}

myclass::~myclass()
{

}

in mainwindow.cpp (i'm using QT)

   myclass *vr = new vr();
   vr->login(ui->linelogin->text(),ui->linepwd->text()); // QString, QString

And I get error:

mainwindow.cpp:31: error: undefined reference to `void ecore::connect(QString, QString)'

What way for using myclass::connect in other classes?

A: 

In the .cpp file, the method is named start(), not login().

Alexander Rafferty
start is a method of 'ecore' and not 'myclass' which should be fine isn't it?
Chubsdad
Sorry, the whole thing is a bit confusing. Where is the definition of class encore?
Alexander Rafferty
+2  A: 
P Daddy
+1  A: 

You should put the implementation of your template function in the header file, not in a .cpp file.

A template's definition needs to be available to the compiler when it should be instantiated. At the point where you call vr->login(...) the compiler needs to have the template's definition (the function body) available to create an instance login<QString>(). If the template function's body is "hidden" in some .cpp file then no function is created, and later the linker complains that it is missing.

sth
so, do u may write simple?
mcuw