Just don't define it:
B():host(A()) {} // This is ugly and not needed !!
That is, the following should do what you want to do:
class B { B(const A& a): host(a) {} private:
The idea is that you have defined a constructor that takes parameter (s), then the default constructor is not generated by the compiler. This means that instances of the above class cannot be created by default!
B b1;
C ++ 11 Solution
In C ++ 11, you can explain, the compiler does not generate a specific constructor, like:
struct B { B(const A &a) {} B() = delete;
Not only this. There is more to this, as described below:
Now the interesting part
You can also selectively disable the constructor for selected types, which makes delete more interesting. Consider this,
struct A { A (int) {} };
An object of this class can be created not only with the int argument, but also with any type that is implicitly converted to int . For instance,
A a1(10); //ok A a2('x'); //ok - char can convert to int implicitly B b; A a3(b); //ok - assume b provides user-defined conversion to int
Now suppose that for some reason I do not want class A users to create objects with char or class B , which, fortunately or unfortunately, can implicitly convert to int , then you can disable them as:
struct A { A(int) {} A(char) = delete;
Now you go:
A a1(10); //ok A a2('x'); //error B b; A a3(b); //error - assume (even if) b provides user-defined conversion to int
Online Demo: http://ideone.com/EQl5R
The error messages are very clear:
prog.cpp: 9: 5: error: remote function "A :: A (char)"
prog.cpp: 10: 5: error: remote function 'A :: A (const B &)'