Kai-Uwe Bux wrote:
Could you post the code you are looking at.
I already posted it in my original post. But fine, to make it clearer,
here's the code divided into a header file and two .cc files:
//------------ foo.hh --------------
#include <iostream>
template<typename T>
void foo(T t)
{
// Uncomment these two lines for the other behavior:
//static int count = 0;
//std::cout << "count: " << ++count << std::endl;
bar(t);
}
//----------------------------------
// ----------- main.cc -------------
#include "foo.hh"
void bar(int i) { std::cout << "int: " << i << std::endl; }
void b();
int main() { foo(5); b(); }
//----------------------------------
// ----------- b.cc ----------------
#include "foo.hh"
void bar(long i) { std::cout << "long: " << i << std::endl; }
void b() { foo(7); }
//----------------------------------
I'm using gcc 4.1.2. Running it like it is above it prints:
int: 5
long: 7
Uncommenting the two lines in the header makes it print:
count: 1
int: 5
count: 2
int: 7