我目前正在开发一个 c++ 程序,主要目的是你有两个不同的对象在屏幕上浮动,相互碰撞等等。无论如何,我遇到的问题是我需要从我的基类派生两个类。但是,在派生类的定义和声明中,我遇到了一个错误并且无法解决。我已经搜索了网络并征求了我的同事的意见,但无法找到问题的根源。代码是
Jetsam(RandomNumber &rnd, Console &console);
(对于头文件)
和
Jetsam::Jetsam(RandomNumber &rnd, Console &console): Element(rnd, console){};
(对于 cpp 文件)
我得到的错误是 IntelliSense:
Jetsam::Jetsam(RandomNumber &rnd, Console &console)" 没有为以下内容提供初始化程序:e:\c++\my game\my game\jetsam.cpp。
有谁知道出了什么问题。任何帮助将非常感激 :)
干杯,阿林。
按照要求:
捷萨姆
#pragma once
#include "RandomNumber.h"
#include "Console.h"
#include "element.h"
#include <iostream>
using namespace std;
class Jetsam : public Element
{
public:
Jetsam(RandomNumber &rnd, Console &console);
~Jetsam();
void printAt(void);
protected:
RandomNumber &rnd;
Console &console;
};
元素
#pragma once
#include "RandomNumber.h"
#include "Console.h"
#include <iostream>
using namespace std;
// code shell, amend as appropriate
class Element
{
protected:
RandomNumber &rnd;
Console &console;
int x;
int y;
int energy;
int direction;
int speed;
char identifier;
static char nextIdentifier;
public:
Element();
Element(RandomNumber &rnd, Console &console);
// precondition: references to RandomNumber and Console objects are provided, along with any other desired parameters
// postcondition: Element object created and private members initialised
// example of use: Element element(rnd, console);
virtual void print(void);
// precondition: none
// postcondition: identifier, x and y are sent to the standard output
// example of use: element.print();
virtual void printAt(void)=0;
// precondition: none
// postcondition: text background is changed proportionate to its energy in the following order
// BLUE, GREEN, AQUA, YELLOW, RED, PURPLE, e.g. an object with 23 energy would have an AQUA background
// object's identifier is sent to the standard output at its x, y coordinates
// example of use: element.printAt();
int getX(void);
int getY(void);
int getEnergy(void);
int getDirection(void);
int getSpeed(void);
//getters for the base class
void setX(int);
void sety(int);
void setEnergy(int);
void setDirection(int);
void setSpeed(int);
//setters for the base class
};