Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
timotheecour opened this issue Jan 22, 2018 · 0 comments
Labels

Comments

@timotheecour
Copy link
Collaborator

//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 timotheecour changed the title Base a=Derived(arg); doesn't work (it tries to call a Base::Base unless there's a dtor) Base a=Derived(arg); doesn't work (it tries to call a Base::Base() unless there's a dtor) Jan 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant