gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Class templates & example makefile

#134878 - jimmy - Tue Jul 17, 2007 10:26 pm

I'm using a Makefile that comes from one of the devkitARM (r20) examples. When trying to use class templates, I get a link error (undefined reference). Having looked through the forum for an hour or so now, I havent managed to find anything useful to me. Is it a problem with the Makefile im using perhaps (as I mentioned, its taken from one of the devkitARM examples)? If so, can anyone please post the required modifications to the example makefile in order to make it work with c++ templates?

Here is the tiny test class that's causing the error:

test.h:

template <typename T>
class Test
{
public:
void DoSomething( T blah );
};


test.cpp:

template <typename T> void Test<T>::DoSomething( T blah )
{
}

#134923 - jimmy - Wed Jul 18, 2007 11:49 am

In case anyone is interested, I moved the definition into the header, and now it works.
If I remember correctly, it is possible to separate the definition from the declaration in a template class in visual c++, not sure though. Apparently this doesn't work with gcc, altough it might just be my complete noobness with gcc & makefiles that is the problem :)

#134924 - PeterM - Wed Jul 18, 2007 11:56 am

As you've hopefully figured out, the definition needs to be in the header.

Otherwise how is calling code in another compilation unit supposed to generate the function body?
_________________
http://aaiiee.wordpress.com/