试图找出如何使用具有继承类的构造函数。我知道这是非常错误的,我一直在写C++约三天了,但这里是我的代码吗:C++继承和构造函数
clientData.h,两班,ClientData扩展实体:
#pragma once
class Entity
{
public:
int x, y, width, height, leftX, rightX, topY, bottomY;
Entity(int x, int y, int width, int height);
~Entity();
};
class ClientData : public Entity
{
public:
ClientData();
~ClientData();
};
和clientData的.cpp,其中所包含的功能:
#include <iostream>
#include "clientData.h"
using namespace std;
Entity::Entity(int x, int y, int width, int height)
{
this->x = x;
this->y = y;
this->width = width;
this->height = height;
this->leftX = x - (width/2);
this->rightX = x + (width/2);
this->topY = y - (height/2);
this->bottomY = y + (height/2);
}
Entity::~Entity()
{
cout << "Destructing.\n";
}
ClientData::ClientData()
{
cout << "Client constructed.";
}
ClientData::~ClientData()
{
cout << "Destructing.\n";
}
最后,我创建一个新的ClientData有:
ClientData * Data = new ClientData(32,32,32,16);
现在,我并不惊讶我的编译器在我身上发出了错误,所以我如何将这些参数传递给正确的类?
的第一个错误(从MVC2008)是 错误C2661:“ClientData :: ClientData”:没有重载函数有4个参数
;第二,它会弹出我似乎什么变化,使是 错误C2512 :'实体':没有适当的默认构造函数可用 谢谢。
你可能想说出你的编译器在你身上发出的什么错误! – LukeN 2010-05-29 13:34:31
阅读C++入门。 – starblue 2010-05-29 13:34:35