Re: Protected Constructor Question
xakee wrote:
Hi,
Suppose i have a class called "baseObject". it has a default
constructor protected (so that only the derived classes can use it)
and another public constructor. Now if i try to do this
BaseObject a();
This is not declaring a variable. It's declaring a function a, which
takes no parameters and returns a BaseObject.
My visual studio 2k3 compiler doenst give any error (but a warning).
but then if i try to do something like
a.Draw();
it gives me an error.
As well it should, since a is not an object.
is this supposed to be like this or this is how VC compiler behaves?
It is suppsoed to be like this.
because whats the point of creating a useless object.
You're not creating a useless object. You're not creating an object at all.
please correct me if im wrong.
You were wrong. Don't take it personal, though, this is asked often
enough that it should probably be a FAQ (I couldn't find it in the FAQ,
though).
{ See the FAQ item titled "Is there any difference between List x; and
List x();?", currently available at <url:
http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.2>. -mod/aps }
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]