Sign in to follow this  
richy486

trouble with stacks

Recommended Posts

richy486    122
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

Share this post


Link to post
Share on other sites
BTownTKD    205
"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 this post


Link to post
Share on other sites
rip-off    10979
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 this post


Link to post
Share on other sites
richy486    122
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 this post


Link to post
Share on other sites
Endar    668
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this