2
我
不知道如果我能有两种类看起来像这样:传承与融合 - 基类的指针指向派生类
//file: Small.h
#pragma once
#include "Little.h"
class Small :
public Little
{
public:
Small(void){}
~Small(void){}
};
和
//file: Little.h
#pragma once
#include <iostream>
#include "Small.h"
using namespace std;
//class Small;
class Little
{
public:
Little(){ s = 0; }
void print(){ cout << "oops!" << endl; }
Small* s;
};
现在我的问题:当我想创建一个“Small”类型的对象并调用它的“print()”函数,VS-2010说“class'Small'没有名为'print()'的成员。什么是解决方案?
谢谢你,但我找到了另一种方式。我的这些类的目的是访问基类函数“print()”。但是,如果我们将“Little”中的指针类型更改为“Little *”,我们仍然可以为其继承分配一个类型为“Small *”的指针。所以,我们可以使用这个函数“print()”。再次感谢你。 –