J
Juha Nieminen
Assume we have these three files:
//--------------------------------------------------------------
// foo.hh
#include <iostream>
template<typename T>
void foo(T value)
{
static int s = 0;
++s;
std::cout << "value:" << value << ", s:" << s
<< ", externalVar:" << externalVar << std::endl;
}
//--------------------------------------------------------------
//--------------------------------------------------------------
// bar.cc
namespace { const int externalVar = 456; }
#include "foo.hh"
void bar()
{
std::cout << "In bar(): ";
foo(200);
}
//--------------------------------------------------------------
//--------------------------------------------------------------
// test.cc
namespace { const int externalVar = 123; }
#include "foo.hh"
void bar();
int main()
{
std::cout << "In main(): ";
foo(100);
bar();
}
//--------------------------------------------------------------
Now we compile test.cc and bar.cc into an executable program. What
should be the output of this program?
//--------------------------------------------------------------
// foo.hh
#include <iostream>
template<typename T>
void foo(T value)
{
static int s = 0;
++s;
std::cout << "value:" << value << ", s:" << s
<< ", externalVar:" << externalVar << std::endl;
}
//--------------------------------------------------------------
//--------------------------------------------------------------
// bar.cc
namespace { const int externalVar = 456; }
#include "foo.hh"
void bar()
{
std::cout << "In bar(): ";
foo(200);
}
//--------------------------------------------------------------
//--------------------------------------------------------------
// test.cc
namespace { const int externalVar = 123; }
#include "foo.hh"
void bar();
int main()
{
std::cout << "In main(): ";
foo(100);
bar();
}
//--------------------------------------------------------------
Now we compile test.cc and bar.cc into an executable program. What
should be the output of this program?