Thought you could do this?

T

Tomás

#include <string>

class blah
{
public:

using namespace std;

string k;

};

int main()
{
blah j;
}


Why not?


-Tomás
 
V

Victor Bazarov

Tomás said:
#include <string>

class blah
{
public:

using namespace std;

string k;

};

int main()
{
blah j;
}


Why not?

Because the 'using' _directive_ shall not appear inside class scope.
See Standard, subclause 7.3.4 Using directive.

V
 
T

Tomás

Victor Bazarov posted:
Because the 'using' _directive_ shall not appear inside class scope.
See Standard, subclause 7.3.4 Using directive.

V

So I there's the necessity to write the "std", as in:

#include <string>

class blah
{
public:

std::string k;

};


I'm writing code that takes a load of names from a particular namespace,
and so it would be handy to do what I originally intended.

-Tomás
 
B

Ben Pope

Tomás said:
Victor Bazarov posted:


So I there's the necessity to write the "std", as in:

#include <string>

class blah
{
public:

std::string k;

};


I'm writing code that takes a load of names from a particular namespace,
and so it would be handy to do what I originally intended.

If it's in a header file, fully qualify everything.

If it's in a source file, just take the directive outside of class scope.

Ben Pope
 
B

benben

I'm writing code that takes a load of names from a particular namespace,
and so it would be handy to do what I originally intended.

-Tomás

Use typedef:

class A
{
private: typedef std::string string;

string a;

// ...
};

Regards,
Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top