J
johnbrown105
Hello All,
I am doing another exercise (I repeat, *exercise*). The (irrelevant to
this
discussion) point is to show that "You can inject a friend declaration
into
a namespace by declaring it within an enclosed class". I have done
this
successfully, but please consider the following program:
//: C10:FriendInjection.cpp
// From Thinking in C++, 2nd Edition
// Available at http://www.BruceEckel.com
// (c) Bruce Eckel 2000
// Copyright notice in Copyright.txt
namespace Me {
class Us {
//...
public:
friend void you();
};
}
// 1
void Me::you(){}
int main() {
Me::you();
return 0;
}
// 2
// defining you() after main() does not compile
// void Me::you(){}
///:~
/////////////////////////////////////////////////////////////////////////
If Me::you() is *defined* at (2) after the call in main(), gcc 4.1.1
says:
"error: 'you' is not a member of 'Me'". If, instead, Me::you is
*defined* at (1),
then it compiles.
MSVC++ Express compiles it either way without a problem, as expected.
Surely this is a bug in gcc?
I am doing another exercise (I repeat, *exercise*). The (irrelevant to
this
discussion) point is to show that "You can inject a friend declaration
into
a namespace by declaring it within an enclosed class". I have done
this
successfully, but please consider the following program:
//: C10:FriendInjection.cpp
// From Thinking in C++, 2nd Edition
// Available at http://www.BruceEckel.com
// (c) Bruce Eckel 2000
// Copyright notice in Copyright.txt
namespace Me {
class Us {
//...
public:
friend void you();
};
}
// 1
void Me::you(){}
int main() {
Me::you();
return 0;
}
// 2
// defining you() after main() does not compile
// void Me::you(){}
///:~
/////////////////////////////////////////////////////////////////////////
If Me::you() is *defined* at (2) after the call in main(), gcc 4.1.1
says:
"error: 'you' is not a member of 'Me'". If, instead, Me::you is
*defined* at (1),
then it compiles.
MSVC++ Express compiles it either way without a problem, as expected.
Surely this is a bug in gcc?