C ++ class is not a base for itself

I'm not quite sure how much information is needed to answer this question, so tell me if additional information is needed.

Im modifying the big code that I wrote when I suddenly came across this message: error: type 'integer' is not a direct base of 'integer' . I know its inheritance problem, but im doesn't inherit other classes.

The code causing this problem is

 integer(const std::string & val, uint16_t base): integer(val.begin(), val.end(), base) {} 

and

 integer(iterator start, iterator end, uint16_t base) 

.

What do I need to do to fix this?

EDIT: im compiling with -std = C ++ 0x, which according to the answers should be able to compile if my compiler is not deprecated: gcc 4.6.2 I think

+7
source share
4 answers

It looks like you are trying to directly call another constructor. You cannot do this in C ++ 03, but you can do just that in C ++ 11 :

 class SomeType { int number; public: SomeType(int new_number) : number(new_number) {} SomeType() : SomeType(42) {} }; 

For this you need g ++ 4.7 or later, 4.6 does not support this function yet, even with -std = C ++ 0x, which I tested in both versions on my system.

+19
source

It is not possible to call other constructors of the same class like this (in C ++ 11 there are delegating constructors). You need to initialize the members of the class (as you probably did in another constructor).

EDIT:

According to C ++ 0x / C ++ 11 Support in GCC , delegating constructors were implemented in GCC v4.7

+4
source

You cannot call the constructor of the same class in the list of initializers of another constructor (in C ++ 03). But you can initialize members accordingly:

 integer(const std::string & val, uint16_t base): _start(val.begin()) _end(val.end()) _base(base) {} 
+3
source

It is not supported in g ++ - 4.6 ("Delegation of Constructors | N1986 | No"), but it is supported in 4.7 .

+1
source

All Articles