【发布时间】:2014-05-22 20:28:25
【问题描述】:
我正在创建一些类,我决定创建一个基本类,其他类将仅继承该基本类
这是我的基本类头
#pragma once
#include "ImageService.h"
class State
{
public:
State( ImageService& is );
~State();
void Update();
};
不用担心方法,它们不是问题。 所以现在我继续创建一个像这样的 IntroState(头文件)
#pragma once
#include "State.h"
class IntroState : public State
{
public:
IntroState(ImageService& imageService);
~IntroState();
GameState objectState;
};
这是cpp文件
#include "IntroState.h"
IntroState::IntroState(ImageService& imageService)
{
//error here
}
IntroState::~IntroState()
{
}
在构造函数中它声明“没有类“State”的默认构造函数”,现在我认为是,State 的默认构造函数需要传递给它的 imageService 引用。那么如何将这个构造函数中的图像服务传递给状态构造函数呢?
【问题讨论】:
-
+1 表示格式不错,实际上几乎是自己回答问题。
标签: c++ inheritance