By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 982 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

Automatic conversion to base class when calling constructor.

P: n/a
I would like to have the compiler bind a Base class const reference to
a temporary object of a Derived class when calling another class
constructor. Please see the code below:

class Base {};

class Derived: public Base {};

class Foo {
public:
Foo(Base const& );

void bar();
};

int main()
{
Foo foo(Derived());

foo.bar();
}

One compiler gives me the following error:
error: expression must have class type foo.bar();

Another compiler also complains:
error: request for member `bar' in `foo', which is of non-aggregate
type `Foo ()(Derived (*)())'

Any idea why?

Mar 13 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Belebele wrote:
I would like to have the compiler bind a Base class const reference to
a temporary object of a Derived class when calling another class
constructor. Please see the code below:

class Base {};

class Derived: public Base {};

class Foo {
public:
Foo(Base const& );

void bar();
};

int main()
{
Foo foo(Derived());

foo.bar();
}

One compiler gives me the following error:
error: expression must have class type foo.bar();

Another compiler also complains:
error: request for member `bar' in `foo', which is of non-aggregate
type `Foo ()(Derived (*)())'

Any idea why?
This is the reason why you see that error.

http://www.parashift.com/c++-faq-lit...html#faq-10.19

HTH
Mar 13 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.