g++: a bug or a feature ???
Gokhan Kisacikoglu
kisa@centropolisfx.com
Mon Jul 15 10:53:00 GMT 2002
This is the correct code:
-----------------------
//main.cc
#include <iostream>
#include "test.hh"
inline void g() { cerr<<"Main.g()\n" ; }
void main() {
g(); // wish to activate g() in main.cc
f(); // wish to activate g() in test.cc through f().
}
//--------end of main.cc
//test.cc
#include <iostream>
#include "test.hh"
namespace test_cc
{
inline void g() { cerr<<"Test.g()\n" ; }
}
void f() {
test_cc :: g(); // wish to activate g() in test.cc
}
---- OR ---------
using namespace test_cc; // in the scope of test.cc
void f() {
g(); // wish to activate g() in test.cc
}
//--------end of test.cc
// test.hh
void f();
//--------end of test.hh
The compiler has to make a decision on which g() to link with, obviously
the first one that is available is the one in main.
Gokhan
More information about the Gcc-help
mailing list