Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

aCC 3.52 behaving in an unexpected way with opeator keyword

Occasional Visitor

aCC 3.52 behaving in an unexpected way with opeator keyword

Hi,

I'm having an issue with the following code:

#include

class A;

class B {
public:
B(A &a) {
print("B::B(...)\n");
}
};

class A {
public:
B begin() {
printf("B::Begin\n");
return(B(*this));
}

operator B () {
printf("cast\n");
return(begin());
}
};

int main() {
A a;
a.begin()
return(0);
}


I would expect this code to output something similar to:

B::begin
B::B(...)

then quite, however it seems that the aCC compiler is calling the operator B () hence going into an infinite loop causing a stack overflow. Changing the A::begin method to the following code makes the program operate as expected:

B begin() {
printf("B::Begin\n");
B b(*this);
return(b);
}

is there some kind of compiler switch or similar that would allow me to get the expected behaviour from the first code example (which compiles and runs as expected using gcc under linux)?




1 REPLY
Highlighted
Acclaimed Contributor Acclaimed Contributor

Re: aCC A.03.52 behaving in an unexpected way with operator keyword

[ Edited ]

This works fine with aCC6. To get it to work with aCC3, you'll have to remove that user conversion function. Or rewrite the code with the temp as you said.