C ++类不是自身的基础 [英] C++ Class is not base of itself

查看:137
本文介绍了C ++类不是自身的基础的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道需要多少信息来回答这个问题,所以告诉我是否需要更多信息。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆