This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: g++: a bug or a feature ???


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]