gcc -dM -E test.cor
g++ -dM -E test.cpp
Software, web, and programming tips: C++, Java, C, Linux, Windows, Cygwin, Firefox, Vim, WWW, RSS
gcc -dM -E test.cor
g++ -dM -E test.cpp
vimrc
:let g:load_doxygen_syntax=1
:help doxygen
//Forward declarations
class OtherClass; // defined in otherClass.h
struct OtherStruct; // defined in otherStruct.h
class MyClass
{
private:
OtherClass *mMyOtherClass; //pointer
OtherStruct &mMyOtherStruct; //reference
public:
MyClass(OtherStruct &_struct);
~MyClass();
};
#include "myClass.h"
// include headers of forward declarations
#include "otherClass.h"
#include "otherStruct.h"
MyClass::MyClass(OtherStruct &_struct)
: mMyOtherClass(new MyOtherClass),
// references can only be initialized in
// constructor initialization list
mMyOtherStruct(_struct)
{
// Empty constructor body
}
MyClass::~MyClass()
{
delete mMyOtherClass;
}
const
Keyword
const
to signify (to developers, not just the compiler) that a variable does not change)./**
* This method doesn't change its object
* @param[in] obj Reference to a constant MyObj
* @return A constant reference to obj
*/
const MyObj& MyObj::myMethod(const MyObj &obj) const
{
return obj;
}
void func(BigObject obj) // Use copy of obj
{
...
}
void func(BigObject &obj) // Uses reference of obj
{
...
}
MyClass::MyClass()
{
member1 = 1;
member2 = 2;
member3 = member2;
}
MyClass::MyClass()
: member1(1),
member2(2)
//, member3(member2) // No guarantee member2
// was set before here
{
member3 = member2; // need to assign here
}