| re: "using namespace" within a class declaration?
"Jacek Dziedzic" <jacek__NOSPAM__@janowo.net> wrote in message
news:c6p955$hje$3@korweta.task.gda.pl[color=blue]
> 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?
>
> TIA,
> - J.[/color]
Both Comeau online and VC++ 7.1 reject both and say that using declarations
must involve base class names. For example, the following won't compile:
#include <iostream>
class A
{
public:
using std::cout;
A()
{
cout << "A constructed\n";
}
};
nor will
#include <iostream>
class A
{
public:
using namespace std;
A()
{
cout << "A constructed\n";
}
};
On the other hand, if you move the using directive/declaration inside a
function, it is a different story. The following is fine:
class A
{
public:
A()
{
using namespace std;
using std::cout;
cout << "A constructed\n";
}
};
--
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead) |