really stuck on visual C++ 6.0

Started by
25 comments, last by yeeha_sf 15 years, 11 months ago
Quote:Original post by frubam

I'd like to ask how "using namespace std" pollutes the global space, as I'm not really sure what that[pollution] entails. I've always just been told that global initializations are bad, and I shouldn't use them, but have never been given a reason why.


Well the idea behind namespaces is that they prevent naming collisions for types and functions. The std namespace has a lot of classes and functions, some with very "generic" names like std::vector. The idea is that you don't want to simply say "give me every class and function in the standard library!" because you might get something with a name you'd like to use yourself (or that's used in a third-party library you're using). Therefore it's generally better practice to specifically state what you're using (for example "using std::vector;" or to simply put the namespace every time you use the class or function.

Advertisement
Quote:Original post by frubam
Thanks Evil Steve, I didn't know that. I'll start using "std::cout" from now on, though it'll probably be annoying until I get it into muscle memory :D.

I'd like to ask how "using namespace std" pollutes the global space, as I'm not really sure what that[pollution] entails. I've always just been told that global initializations are bad, and I shouldn't use them, but have never been given a reason why.
Doing "using namespace std" tells the compiler "Wherever you find an unrecognised symbol, see if it exists in the std namespace, as if I'd prefixed it with 'std::'" (Well, more or less). That can mean that some functions that are in the std namespace, like find() get confused with functions that you create called find().
The functions in the std namespace are designed to be referred to by the namespace name, which is why they have relatively simple names like find().

You can do "using std::cout;" as well, which means you don't want to have to type the std:: prefix only with cout, which is a lot more acceptable. But I'd still recommend against putting any "using" clauses in a header they should only go in a source file, so you don't accidentally pollute another .cpp file that includes that header.

If you have any more questions about this stuff, it might be better to start a new thread rather than taking this one off topic [smile]
I get it now, thanks. I did notice when I'd use variable names or functions like count or length, it would show up as something different when I accessed it, but never knew why. Sorry for going off topic :( .
OMG, Dave Hunt, I can 't believe ALL the time it 's been MY mistake - I missed only 1 but CRITICAL line and that 's the only thing that was breaking my program - I thought I had all the program rewritten exactly, but thanks to your tip I checked the exact place - I couldn 't really check it all - THANKS :

wc.hCursor = LoadCursor(NULL, IDC_ARROW);

NOW IT WORKS !
Quote:Original post by yeeha_sf
wodinoneeye, you really must be some kind of wizzard for what you 're saying and it sounds really great, but I 'm telling you I can 't make even one program work on VC++6.0 - it 's unexplainable to me how exactly the effect with the .EXE file is achieved in the downloadable code from lesson1, but I already mentioned that, whatever... I just have some last questions - like an all-new beginner, can you recommend me the best latest OpenGL book about C++, is that the 5th edition of the Red book or there are better books, but also good as explaining things to guys like me? And also, are C++ materials too far away from Java ones? Because you see, I have the nearly latest Java tools, but when I can 't use them - is there, say, some equivalent to the latest Red book, but in Java variataion and can you recommend me something? The latest version of OpenGL is 2.0, is it? I 'm definitely going to update my C++ tools, but after I 'll be starting from newer versions, I 'm going to need some very well explaining materials.


Man I wish my website was farther along after reading this post. If you can hold out a few weeks I will be posting a website with a lot of beginner stuff that starts from hello world and continues through to wherever I am currently at in learning. I make posts on it everytime I learn something new and describe what I learned, with plenty of exercises to try out as well. Unfortunatly I am still in the stage of catching it up to where I am at as well as ensuring all the information is as accurate as I can make it : /
Quote:Original post by yeeha_sf
OMG, Dave Hunt, I can 't believe ALL the time it 's been MY mistake - I missed only 1 but CRITICAL line and that 's the only thing that was breaking my program - I thought I had all the program rewritten exactly, but thanks to your tip I checked the exact place - I couldn 't really check it all - THANKS :

wc.hCursor = LoadCursor(NULL, IDC_ARROW);

NOW IT WORKS !


You're quite welcome! Glad you got it working.
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main

Debug/rewq.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

rewq.exe - 2 error(s), 0 warning(s)

That happens every time when I close my .CPP file and open it again to write some new code - just give me an advice - how to make it compile and build again without those errors ?

This topic is closed to new replies.

Advertisement