2 questions - pure api and namespaces
first question is i'm trying to write a program the "pure api" way and i've got everything working but its taking all the CPUs time.
2nd, im assisting in a computer science 4 class and the teacher is new (he's just learning C++ with the students) and he wants to know about namespaces. So i told him what they're for and that you need something to the affect of using namespace std; for all the new header files and that its recommended that you use the new header files, but he still wants to know why? im not sure if i understand what he's asking, maybe he wants to know why microsoft made new headers for things and put everything in a standard namespace?
Re: 2 questions - pure api and namespaces
Quote:
Originally posted by DNA7433
first question is i'm trying to write a program the "pure api" way and i've got everything working but its taking all the CPUs time.
2nd, im assisting in a computer science 4 class and the teacher is new (he's just learning C++ with the students) and he wants to know about namespaces. So i told him what they're for and that you need something to the affect of using namespace std; for all the new header files and that its recommended that you use the new header files, but he still wants to know why? im not sure if i understand what he's asking, maybe he wants to know why microsoft made new headers for things and put everything in a standard namespace?
I thought the new guy was supposed to be good :confused:
Anyway, It wasnt Microsoft that decided to create new headers. It was the standards committee. The older headers (<iostream.h>, etc) are only there for compatibility's sake. The new headers all lose the ".h", and everything within them is inside the std namespace. Namespaces allow for several codebases to be sued within the same application. For instance, If I was writing a game, and needed a vector class to hold my object's position, without namespaces, id have to call it something other then "vector" for the code to even compile. With the name space, I have my "vector", but I can also use the vector container, because it is within the std namespace (std::vector).
To use the namespace, you CAN use "using namespace <name>", but it is recommented that you only use the parts you need, ie:
Code:
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
...
cout << "blah" << endl;
string x("Hello");
...
For smaller programs, this isnt a big deal, but when your code base gets huge, you dont want your global namespace to be cluttered.
As for your first question, do you have a Message pump?
Code:
If(GetMessage(...))
{
TranslateMessage(...);
DispatchMessage(...));
}
Z.