I have a very, very strange situation. I code that sorta looks like this:
class Foo
{
public:
template <class T>
int doSomething()
{
std::cout << "Hello world!";
}
};
If I try to call doSomething like this:
std::cout << "Pre";
doSomething<int>();
std::cout << "Post";
Conclusion:
Pre
Post
I am not getting Hello World output, and nothing in the function is being executed. Naturally, this means that my program will work a bit later, because I needed to execute this function.
However, if I specialize in a pattern:
template <>
int doSomething<int>()
{
std::cout << "Hello World int!";
}
Then my conclusion:
Pre
Hello World int!
Post
This does not happen on Windows or Linux, only on Mac - and only versions that compiled on an older version of Mac OS.
Is there anything in the standard or how are general compiler implementations that can cause this behavior? Where, if you do not specialize the template, the template is not called?
, , , . , . , .
, , , - . , , , - !
, , , , . - - , , , , , ?
: . , , , , ! !
g++ 4.2 (GCC 4.2.1 Apply Inc. build 5658)
. , QtCreator , . , , Qt, , , .