typedef and array as parameter

I am an very beginner and try this in codeblock,windowXP.

main.cpp as followed
1
2
3
4
5
6
7
8
9
10
11
class printtt;
using namespace std;
typedef unsigned int type_num;
int main()
{
    type_num asdf[3];  //if changed to "int asdf[3];", it has no error why?
    asdf[0]=4;
    printtt::nothing(asdf,4); //<-- error here \testOnly\main.cpp|13|undefined 
       //reference to `void printtt::nothing<unsigned int>(unsigned int*, int)
    return 0;
}


printtt.cpp as followed
1
2
3
using namespace std;
typedef unsigned int type_num;
 template<typename TTT>  void printtt::nothing(TTT* t,int size){};


printtt.h
1
2
3
4
5
using namespace std;
using std::cout;
class printtt{
    public: template<typename TTT> static void nothing(TTT* t,int size);
};


but in main.cpp if changed "type_num" to "unsigned int" (not use typedef) it will have no error.

I don't want to omit "typedef" and replaced a plain type "unsigned int", is it possible not to have the error? Thank in advance.
I don't know why int works, but generally, definition of a template function must be 'visible' when the function is called. This means you have to put it inside a header.
Thank hamsterman, I get it !!!
I didn't understand what hamsterman said enough and read my book again, it said that a function in class that use template must 1.inline function or 2. in the "same" file of the function declaration only. It's just what hamsterman had already said.
printtt.h
1
2
3
4
5
6
7
8
9
#ifndef PRINTTT_H_INCLUDED
#define PRINTTT_H_INCLUDED
#include <iostream>
class printtt{
    public: template<typename TTT> static void nothing (TTT* t,int size);
                                   static void nothing2(int* t,int size);
};
template<typename TTT> void printtt::nothing (TTT* t,int size){}
#endif // PRINTTT_H_INCLUDED 
Topic archived. No new replies allowed.