Calypso icon indicating copy to clipboard operation
Calypso copied to clipboard

`Base a=Derived(arg);` doesn't work (it tries to call a Base::Base() unless there's a dtor)

Open timotheecour opened this issue 7 years ago • 0 comments

//util.h:
struct A3{
	int a;
	// A3(){ printf("A3::A3\n"); }
	A3(int a):a(a){}
};

struct A3Derived:public A3{
	double a2;
	A3Derived(int a, double a2):A3(a),a2(a2){}
};

// main.d:
A3 a3d2=A3Derived(1,1.5);
// Problem 1:
// Error: constructor ℂcpp.tims.A3.A3.this (int a) is not callable using argument types ()

Now uncomment A3(){ printf("A3::A3\n"); }

A3 a3d3=A3Derived(1,1.5);
// works but calls A3(), then A3::A3(int), then A3Derived::A3Derived
// Problem 2: why does it call A3()?

Now add virtual A3::~A3() {printf(...)} and virtual A3Derived::~A3Derived(){ printf(...) } => problem 2 disappears => problem 1 disappears (ie removing A3::A3() does not cause problem 1)

timotheecour avatar Jan 22 '18 01:01 timotheecour