Public Group

# trouble with stacks

This topic is 4447 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Im having trouble using an stl stack in C++:
#pragma once

#include <string.h>
#include <stdio.h>
#include <stack>

class CConsole
{
protected:
stack<char> sCommands;
public:
CConsole(void);
~CConsole(void);
};


I get the errors: error C2143: syntax error : missing ';' before '<' error C2501: 'CConsole::stack' : missing storage-class or type specifiers error C2238: unexpected token(s) preceding ';' all at the stack<char> sCommands; line

std::stack<char>

##### Share on other sites
oh yeah, i remember now, thanks!

##### Share on other sites
"using namespace std;"

add that line to avoid having to type std:: before every stack instantiation. (Also helps with std::cout if you end up using the iostream library, and std:string in the string library)

##### Share on other sites
Quote:
 Original post by BTownTKD"using namespace std;"add that line to avoid having to type std:: before every stack instantiation. (Also helps with std::cout if you end up using the iostream library, and std:string in the string library)

Yes, but that file looks like a header.

It is better to not use "using" directives in a header file.

##### Share on other sites
Quote:
 Yes, but that file looks like a header.It is better to not use "using" directives in a header file.

Yes it is a header, why is it best not to use using in a header?

##### Share on other sites
Because then every single file that the header is included in will have the 'using' applied to it.

Usually with the standard C++ stuff like STL, it's not a big deal, but when you start a project that has multiple namespaces and nested namespaces, and you could even have classes and functions with the same name inside completely unrelated namespaces, it's better to specify, otherwise you'll probably get a redefined error......

Ah, well, it's not too bad, at least if you have VC++ 2005 express. I tested it and it gave me an "ambiguous call to overloaded function" error and then went on to say it could be "blah" or it could be "blah".

But anyway, you'll run into those problems.

• 10
• 16
• 14
• 18
• 15
×

## Important Information

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!