Jacek said:
Is it valid to use a "using namespace foo"
(as opposed to using foo::bar which I'm sure is legal)
within a class declaration?
My compiler rejects it, but I've been told it's valid.
Can anyone please confirm or deny?
cat test.cc
#include <iostream>
class X {
private:
// representation
int I;
public:
using namespace std;
using std::endl;
X(int i = 0): I(i) {
cout << "X(" << i << ")" << endl;
}
};
int main(int argc, char* argv[]) {
X x(13);
std::cout << "The end!" << std::endl;
return 0;
}
g++ -Wall -ansi -pedantic -o test test.cc
test.cc:8: parse error before `namespace'
test.cc:9: using-declaration for non-member at class scope
test.cc: In constructor `X::X(int)':
test.cc:11: `cout' undeclared (first use this function)
test.cc:11: (Each undeclared identifier is reported \
only once for each function it appears in.)
test.cc:11: `endl' undeclared (first use this function)
test.cc: In function `int main(int, char**)':
test.cc:16: warning: unused variable `X x'