C ++类不是自身的基础 [英] C++ Class is not base of itself
问题描述
我不知道需要多少信息来回答这个问题,所以告诉我是否需要更多信息。
Im not exactly sure how much information is needed to answer this, so tell me if more information is needed.
我修改了一个大代码,当我突然遇到此消息:错误:类型整数不是整数的直接基础
。我知道它的继承问题,但不是继承其他类。
Im modifying a large code i wrote when i suddenly encountered this message: error: type 'integer' is not a direct base of 'integer'
. i know its an inheritance problem, but im not inheriting other classes.
导致此问题的代码是
integer(const std::string & val, uint16_t base): integer(val.begin(), val.end(), base) {}
和
integer(iterator start, iterator end, uint16_t base)
已定义。
我需要做什么来解决这个问题?
What do I need to do to fix this?
编辑:im编译与-std = c ++ 0x,根据答案,我应该能够编译,除非我的编译器老:gcc 4.6.2我想
im compiling with -std=c++0x, which according to the answers, i should be able to compile, unless my compiler is old: gcc 4.6.2 i think
推荐答案
重新尝试直接调用另一个构造函数。你不能在C ++ 03中做到这一点,但是你可以做到在C ++ 11 < a>:
It looks like you're trying to call another constructor directly. You can't do that in C++03, but you can do exactly that in C++11:
class SomeType {
int number;
public:
SomeType(int new_number) : number(new_number) {}
SomeType() : SomeType(42) {}
};
您需要g ++ 4.7或更高版本才能正常工作, 4.6不支持此功能,即使使用-std = c ++ 0x,我在我的系统上用这两个版本测试。
You'll need g++ 4.7 or newer for this to work, 4.6 doesn't support this feature yet, even with -std=c++0x, which I tested with both versions on my system.
这篇关于C ++类不是自身的基础的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!