Hi -
Quote:
: what's the meaning of explicit? like this:
"explict vector( int theSize =0) : m_CurrentSize( theSize)"
|
There are three things going on here:
1. He's declaring parameter "theSize", type int, with default value of "0"
2. He's initializing class member "m_currentSize"
... and, the answer to your main question ...
3. "explict" can be anything. It's probably a "#define" in some header file somewhere.
You should be able to "grep" for it wherever this program's header files live.
Here's one example I found on google (from an STL header file):
Code:
# ifdef __STL_NEED_EXPLICIT
# define explicit
# endif
In this case, "explicit" is a macro that means <<blank space - nothing at all>>
If somebody had source code like you have above (with "explicit" in the declaration), and "__STL_NEED_EXPLICIT" wasn't defined ... then they'd get a compile error.
Quote:
2: Is it correct that include source file at the end of head file? like this:
#ifndef VECTOR_H
#define VECTOR_H
...
..
include "Vector.cpp"
#endif
|
Syntactically correct? Yes. Wise? It depends... In this case? It's undoubtedly needed to make sure a client who includes the header (which defines the interface) also has access to the template implementation code (in C++, the compiler needs to see the actual source in order to instantiate the template).
Quote:
3:
~vector()
#ifndef WIN32
{
delete[] m_pObjects;}
#else
{
if(m_CurrentSize !=0 )
delete [] m_pObjects;
}
#endif
my question is when and how to set WIN32????
|
1. "#define WIN32" in the source will work.
2. "-D" from the command line will also work.
3. "/DWIN32" happens automagically when you use Microsoft's Visual Studio (for example) to build a Windows app.
4. If you're *NOT* compiling for Windows, you probably DON'T want to manually "#define" WIN32. If you *ARE* programming on Windows, it's probably happening for you automatically.
Here's one easy way to check - try compiling this:
Code:
#if defined(WIN32)
#error I guess WIN32 is defined!
#endif
'Hope that helps .. PSM