Re: aCC A.03.52 behaving in an unexpected way with operator keyword (30 Views)
Reply
Occasional Visitor
Joss
Posts: 1
Registered: ‎10-30-2006
Message 1 of 2 (30 Views)

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)?




Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,956
Registered: ‎03-06-2006
Message 2 of 2 (30 Views)

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.

Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation