Hi @all,
I've got (probably) a simple question. When do I have to declare a function used in a template? The following code prints out (using gcc >=4.1):
init my A object
no init
Using gcc 4.0 the following code prints out:
init my A object
init my string object
#include <iostream>
#include <string>
template<typename T>
void init(T& t){
std::cout << "no init" << std::endl;
}
// void init(std::string& t);
template <typename T>
void doSomething(T& t){
init(t);
// do some further stuff
}
void init(std::string& t){
std::cout << "init my string object" << std::endl;
}
class A{
};
void init(A& t){
std::cout << "init my A object" << std::endl;
}
int main(){
A a;
doSomething(a);
std::string s("test");
doSomething(s);
return 0;
}
What is the difference between the usage of std::string and A? Shouldn't there be the same behaviour?
With the additional forward declaration it works fine, but when do I need it?
Cheers, CSpille