Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Brobanx

Need lots of help with STL =[

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been trying all day just trying to make a vector! I almost made my own CArray class before starting to look everywhere on tutorials for STL and such, but none of them tell me anything about what I need to know.
        
#include <vector>


vector<int> intarray;
      
Every time I try to compile, it gives me the error C2501: 'vector' : missing storage-class or type specifiers. I looked at my include files and all the STL files are in there (I'm using Visual C++ 6.0), but for some reason the compiler's thinking that vector isn't defined. Edited by - Brobanx on December 17, 2001 7:43:13 PM

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
///do this
#include <vector.h>

std::vector<int> someints;

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
using namespace std; is just a lot easier though, or you''ll encounter this problem with other standard types.

Share this post


Link to post
Share on other sites
using std::vector;
is the ''preferred'' method, or so I''ve been told.
That way you just get what you want, not everything in namespace...

Magmai Kai Holmlor

"Oh, like you''ve never written buggy code" - Lee

"What I see is a system that _could do anything - but currently does nothing !" - Anonymous CEO

Share this post


Link to post
Share on other sites
The way we do it here (at work):

In header files, "using" is not allowed. Period. Every STL name (e.g. in arguments or as members of classes) has std:: in front of it. Even "using std::list" is dangerous in a .h file--you''ll dictate that every list in every .h file included after that one for every client is a std::list.

In .c files, use whatever you want. Mostly we import the entire std namespace, unless we have conflicts in our files with other modules, then we''re selective.

Share this post


Link to post
Share on other sites
Stoffel:

Why not use a project namespace? Then divy it up into namespaces for organizational purposes. I would think that this approach would cut down on the possibilities of name conflicts within the project, too.

I give each source/header file pair a project namespace and one or more subnamespaces according to what it does, i.e.:

Filenames:

ide.h
ide.cpp
ide_cpp.h
ide_cpp.cpp
ide_cpp_preprocessor.h
ide_cpp_preprocessor.cpp
ide_cpp_parser.h
ide_cpp_parser.cpp
ide_cpp_compiler.h
ide_cpp_compiler.cpp
ide_java.h
ide_java.cpp
ide_java_compiler.h
ide_java_compiler.cpp
ide_java_compiler_dynamic.h
ide_java_compiler_dynamic.cpp
ide_java_compiler_static.h
ide_java_compiler_static.cpp
ide_java_interpreter.h
ide_java_interpreter.cpp

Namespaces:

ide
cpp
preprocessor
parser
compiler
java
compiler
dynamic
static
interpreter


(This approach would be great if MSVC's ClassView would recognize namespaces. I suppose you could replace the filename prefixes with folders and subfolders, and then use FileView to browse the project. I think that this is similar to what Java does automatically - creating namespaces from filenames.)

Then I place non-namespace using statements at the top of the smallest possible scope to indicate dependencies. This separates the dependencies from the actual code and makes the bodies of the classes, functions, and so forth much more readable without the possibility of messing up any other files.

The frustrating thing about classes is the way that namespaces interact with classes. Why can I not place a namespace within a class to add optional prefixes? Instead I must resort to using multi-word identifiers with underscores or capitalization...blech.

- null_pointer

Edited by - null_pointer on December 18, 2001 11:01:04 AM

Share this post


Link to post
Share on other sites
using namepace std; is ok if you plan on using the STL version of the object throughout. If you only want to use std::string and you have defined your own vector class, then don''t use the namespace line. The std::vector will be used instead of your class.

-----------------------------
kevin@mayday-anime.com
http://games.mayday-anime.com

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!