|
|
|
|||||
|
Generated constructors in derived classes do not pass params correctly to base class
Hello,
When I pass a parameter through a base class constructor it does not seem to get set into the base class member variable. Here is a small repo case to demo the problem. (Ice version is 3.3.0 for C++) Code:
--- demo.ice. ---
module demo
{
enum ShapeType {
Unknown,
RectangleType,
TriangleType,
CircleType,
SquareType
};
class Shape {
ShapeType type;
};
class Circle extends Shape {
int radius;
};
sequence<Shape> ShapeSeq;
};
-- demoTest.cpp --
#include "demo.h"
#include <iostream>
#include <assert.h>
using namespace std;
using namespace demo;
class CircleI : virtual public Circle
{
public:
CircleI(int rad)
: Circle(CircleType, rad)
{
cerr << "Circle of radius:" << radius
<< " type:" << type << endl;
assert(type == CircleType);
}
};
int main(int,char *[])
{
ShapeSeq shapes;
shapes.push_back( new CircleI(20) );
}
./demo Circle of radius:20 type:0 Assertion failed: type == CircleType, file demoTest.cpp, line 15 Compilation abort (core dumped) at Thu Mar 26 10:38:23
__________________
John Basrai Software Engineer Northrop Grumman Mission Systems/ISD |
|
|||||
|
Thanks it works now!
./demoIt seems strange to call two base class constructors but it is better than than setting it in the body of the derived constructor which was the only work around that I had. Thanks for the prompt reply, -john |
|
|||||
|
This seems like a really bad thing from the perspective of avoiding duplicate code...now instead of having constructors that neatly cascade, I have a mountain of redundant initialization code that grows with every new class specialization.
Is there no way around this? |
|
||||||
|
Hi Nick,
There is no way-around, as it is a consequence of mapping Slice class inheritance to virtual inheritance in C++. We've changed this mapping in the upcoming 3.4 release (to use non-virtual inheritance by default) to avoid this often surprising behavior. Best regards, Bernard |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| enumerate derived class names of a given slice class | peterlspot | Comments | 1 | 11-29-2007 08:26 AM |
| Helper Classes not Generated | zhi | Help Center | 5 | 01-04-2007 08:18 AM |
| Base Class For Ref-Counted Classes? | acbell | Help Center | 2 | 03-06-2006 06:32 PM |
| generated C# classes don't have constructors with arguments for fields | kovacm | Bug Reports | 1 | 08-07-2005 08:00 PM |
| bug when pass a class by value | damingyipai | Bug Reports | 2 | 04-02-2004 03:51 AM |