可以声明此类的指针,但对象就不行。可以此类的形参,但是具体到底可以做那一些呢?
/*---------------------------------------------------------------------------
File name: declVSdefn.cpp
Author: HJin (email: fish_sea_bird [at] yahoo [dot] com )
Created on: 7/5/2007 15:18:47
Environment: Windows XP Professional SP2 English +
Visual Studio 2005 v8.0.50727.762
Modification history:
===========================================================================
The following code compiles under MS VS 2005.
defn === definition
decl === declaration
forward decl is used when you need to know the name
of a type before the defn of that type.
If you don't have defn of a type, you can only play with the type name.
You cannot do anything that is meaningful for that type, simply because
you cannot construct an object of that type.
*/
#include <iostream>
#include <string>
using namespace std;
class B; // forward decl
class A
{
public:
void f(B& rObjB, B* pObjB, B objB); // ok --- you declare f() instead of define
/**
wrong --- you are defining g(). need to define B first.
*/
/*
void g(B& rObjB, B* pObjB, B objB)
{
}
*/
private:
//B objB; // wrong --- need to know the defn to allocate memory space for objB
B& rObjB; // reference --- ok
B* pObjB; // pointer --- ok
static B sObjB; // static --- ok
};
int main(int argc, char** argv)
{
return 0;
}