为什么使用前置声明?
A.h
#pragma once
namespace TEST
{
class A
{
public:
A(void)
{
}
virtual ~A(void)
{
}
};
}
B.h
#pragma once
namespace TEST
{
class A;
class B
{
public:
B(void);
virtual ~B(void);
private:
TEST::A *m_Test;
};
}
B.cpp
#include "stdafx.h"
#include "B.h"
#include "A.h"
namespace TEST
{
B::B(void)
{
m_Test=new TEST::A();
}
B::~B(void)
{
delete m_Test;
m_Test=NULL;
}
}
main.cpp
#include "stdafx.h"
#include "B.h"
using namespace TEST;
int _tmain(int argc, _TCHAR* argv[])
{
B *test=new B();
delete test;
return 0;
}