C++ 重新定义抽象基类
C++ Redefinition of abstract base class
使用派生类可以构建的构造函数实现抽象基类。我在编译代码时遇到问题,我提前为使用命名空间 std 道歉;这是我的任务中必需的。
我尝试了标题保护并检查我的包含代码。我将文件分为主文件(Assn2(,抽象基类(S2D(.h和.cpp文件。
在主文件 Assn2 中
#include <iostream>
#include <string>
#include <fstream>
#include "S2D.h"
在 S2D.h 内
#ifndef _S2D_H_
#define _S2D_H_
#include <iostream>
#include <string>
using namespace std;
class ShapeTwoD {
private:
string name;
bool containsWarpSpace;
public:
ShapeTwoD();
ShapeTwoD(string, bool);
在 S2D 中.cpp
#include <iostream>
#include <string>
#include "S2D.h"
using namespace std;
class ShapeTwoD {
ShapeTwoD::ShapeTwoD() {
name = " ";
containsWarpSpace = false;
}
ShapeTwoD::ShapeTwoD(string Name, bool ContainsWarpSpace) {
name = Name;
containsWarpSpace = containsWarpSpace;
}
};
这是我收到的错误。
S2D.cpp:7:7: error: redefinition of ‘class ShapeTwoD’
class ShapeTwoD {
^~~~~~~~~
In file included from S2D.cpp:3:
S2D.h:7:7: note: previous definition of ‘class ShapeTwoD’
class ShapeTwoD {
^~~~~~~~~
make: *** [S2D.o] Error 1
只是一个后续问题,我正在尝试基于这个抽象基类实现派生类。我正在尝试创建基于这些抽象构造函数的派生类构造函数,这些构造函数具有更多参数。
例如。
Rectangle::Rectangle(string Name, bool ContainsWarpSpace, int YSize, int XSize, int(*ArrY), int (*ArrX) )
我想知道我在Java中学到的这个概念在C++中是否可行?
在
S2D中.cpp
#include <iostream>
#include <string>
#include "S2D.h"
using namespace std;
类 ShapeTwoD {//删除此行
ShapeTwoD::ShapeTwoD() {
name = " ";
containsWarpSpace = false;
}
ShapeTwoD::ShapeTwoD(string Name, bool ContainsWarpSpace) {
name = Name;
containsWarpSpace = containsWarpSpace;
}
};删除此行
相关文章:
- 如何定义一个纯抽象基类
- 将抽象基类中的所有纯虚函数定义为 varaidaic 模板
- 在C++单元测试上下文中,抽象基类是否应将其他抽象基类作为函数参数
- 有没有一种方法可以使用SFINAE来检测一个类型是否实现了给定的抽象基类
- 自定义异常中的用户定义的空构造函数,具有多个继承和抽象基类
- 如何保存指向抽象基类的指针/引用,但在 c++ 中仍然可以复制
- C++:在共享对象中调用抽象基类构造函数/未定义的符号
- 从抽象基类中获取重载函数
- 如何构建一个 Map,其中键是抽象基类(而不是值)
- 无法调用纯抽象基类超载
- 私下继承C++抽象基类是什么意思
- 如何在抽象基类中实现运算符+
- 如何为抽象基类创建模板实例化?
- 崩溃 __cxxabiv1::__cxa_pure_virtual () - vtable ptr 到抽象基类
- CRTP - 是否可以创建一个抽象基类?
- 嵌套抽象基类的泛型模板
- 抽象基类的派生类未正确覆盖基纯虚拟方法
- 在C 中的数组中存储抽象基类的不同派生类的对象
- "Has a" C++关系,最佳做法是让一个类"implement"多个抽象基类?
- C++ 重新定义抽象基类