C++中,转换构造函数为什么不能定义为类成员函数?
来源:百度知道 编辑:UC知道 时间:2024/05/13 18:40:44
C++中,转换构造函数为什么不能定义为类成员函数?
C++中,转换构造函数为什么不能定义为类成员函数?
//C.h
class C
{
public:
C();//构造函数定义
~C();//析构函数定义
};
//C.cpp
#indlude "C.h"
C::C(){...}//构造函数实现
C::~C(){...}//析构函数实现
//D.h
class D:classC//D继承C
{
...
};
以上是一个框架
以下是一个实例 为节省空间 定义和实现写到一起了
//TreeBaseNode.h
#pragma once
#include <iostream>
using namespace std;
class CTreeBaseNode
{
public:
CTreeBaseNode(int t)
{
m_Type = t;
m_L = 0;
m_R = 0;
m_P = 0;
}
virtual ~CTreeBaseNode()
{
m_L = 0;
m_R = 0;
m_P = 0;
}
virtual void Show() = 0;
int m_Type;
CTreeBaseNode* m_L;
CTreeBaseNode* m_R;
CTreeBaseNode* m_P;
};
//TreeNodeA.h
#pragma once
#include "treebasenode.h"
class CTreeNodeA :
public CTreeBaseNo