分类:
2008-10-13 16:30:21
I summarize some case which is declaration in C++, and other is defination as bellow
Declaration:
int foo(int,int); //function declaration
typedef short INT16; //typedef declaration
extern int var; //external declaration
class bar; // class declaration, you also use struct,union,enum
friend test; // friend declaration
using std::cout; // namespace declaration
Defination:
int y;
class foo {...};
struct bar {...};
foo* p;
static int i;
enum Color{RED,GREEN,BLUE};
const double PI = 3.1415;
union Rep{...};
void test(int p) {};
foo a;
bar b;
Declaration and Defination in a Class:
// A.h header file
// class A is a defination.
class A
{
public:
int a; // a is a defination
static int b; // b is a declaration, you will difine it outside this class
int getValue(); // method getValue is a declaration., you will difine it outside this class
// method getValue1 is a defination, it is an inline function.
int getValue1()
{
return a;
}
};