Author |
Message |
Null

|
Posted: Sat Nov 25, 2006 11:34 am Post subject: (No subject) |
|
|
I know it seems like a lot of extra typing, but I just prefix all standard library things with std:: instead of using namespace std. I always know what I haven't written myself (part of the standard library), and it makes code easier to read IMHO. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Mr. Gruntsworthy

|
Posted: Sun Nov 26, 2006 1:14 pm Post subject: (No subject) |
|
|
for me, i always use Using Namespace std; i was just taught by the book to do it that way. |
|
|
|
|
 |
wtd
|
Posted: Sun Nov 26, 2006 1:15 pm Post subject: (No subject) |
|
|
Understanding why you do that is more important than knowing how to. |
|
|
|
|
 |
Mr. Gruntsworthy

|
Posted: Sun Nov 26, 2006 1:19 pm Post subject: (No subject) |
|
|
i understand why you use using namespace std;, its because it immediately makes that library available to the whole program if you announce it before or after your #includes, whereas the std:: prefix you have to use before every cout and cin |
|
|
|
|
 |
wtd
|
Posted: Sun Nov 26, 2006 1:34 pm Post subject: (No subject) |
|
|
It doesn't affect whether or not you can use the code in the header. It simply includes the "std" namespace into your program's namespace, such that members of the std namespace declared in any header files that have been included can be used without explicitly denoting the namespace they were declared in.
Consider:
code: | namespace foo
{
int bar()
{
return 42;
}
}
int main()
{
cout << foo::bar() << endl; // ok
using foo::bar; // also ok
cout << bar() << endl;
using namespace foo; // also ok
cout << bar() << endl;
} |
|
|
|
|
|
 |
Mr. Gruntsworthy

|
Posted: Mon Nov 27, 2006 11:04 am Post subject: (No subject) |
|
|
well, i think for the sake of simplicity, im going to stick with the way i was taught, until i learn most of the language. |
|
|
|
|
 |
md

|
Posted: Mon Nov 27, 2006 5:10 pm Post subject: (No subject) |
|
|
Mr. Gruntsworthy wrote: well, i think for the sake of simplicity, im going to stick with the way i was taught, until i learn most of the language.
If your taught something that is wrong and you stick to it you will most likely suffer later on. It's much better to know something is right then simply know it works. |
|
|
|
|
 |
Mr. Gruntsworthy

|
Posted: Mon Nov 27, 2006 11:02 pm Post subject: (No subject) |
|
|
but whats wrong with announcing using namepace for the whole program? |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
md

|
Posted: Mon Nov 27, 2006 11:26 pm Post subject: (No subject) |
|
|
The same thing with including headers you don't use. The more things you include in your source, and the more things you include in your namespace; the more likely you are to run into nameing collisions. Using std::* instead of using namespace std; also increases readability because it's easy to pick out code that uses the standard libraries (and you really don't need to debug the stl... it's best not to try).
Yes, both ways work; but one is better then the other.  |
|
|
|
|
 |
Mr. Gruntsworthy

|
Posted: Tue Nov 28, 2006 8:07 am Post subject: (No subject) |
|
|
Oh well... back on topic, one of my most common mistakes is spelling errors. Every time i write some code i have to go through it and find errors i made while typing. |
|
|
|
|
 |
Andy
|
Posted: Tue Nov 28, 2006 6:46 pm Post subject: (No subject) |
|
|
okay, this one isnt exactly c++, but it killed me.
when debugging your code, make sure you check every single line, even the obvious ones. forgetting to clear the Z buffer in a d3d application will give you the strangest results. |
|
|
|
|
 |
Mr. Gruntsworthy

|
Posted: Wed Nov 29, 2006 2:04 pm Post subject: (No subject) |
|
|
erm... I dont even know what that is... as ive stated, ive only just started learning C++ a little while ago... |
|
|
|
|
 |
Clayton

|
Posted: Wed Nov 29, 2006 5:42 pm Post subject: (No subject) |
|
|
check your loop's conditions, the difference between a < or a > can be a significant one! |
|
|
|
|
 |
Mr. Gruntsworthy

|
Posted: Wed Nov 29, 2006 6:59 pm Post subject: (No subject) |
|
|
okay, so would
Quote: while (variable <= 100)
mean that the variable has to be 99 or under to exit the while loop? And what are the other loops[/quote] |
|
|
|
|
 |
Clayton

|
Posted: Wed Nov 29, 2006 7:05 pm Post subject: (No subject) |
|
|
as long as your variable is under 100, that loop will continue to run, so if that condition is true, the loop continues, if it is false, it exits. |
|
|
|
|
 |
|