Re: How to prevent a function in base class being overloaded from child class
From: modemer (me_at_privacy.net.invalid)
Date: 03/22/05
- Next message: Howard: "Re: Class to support keywords."
- Previous message: Jason Heyes: "Re: Class to support keywords."
- In reply to: Andrey Tarasevich: "Re: How to prevent a function in base class being overloaded from child class"
- Next in thread: David Harmon: "Re: How to prevent a function in base class being overloaded from child class"
- Reply: David Harmon: "Re: How to prevent a function in base class being overloaded from child class"
- Reply: Howard: "Re: How to prevent a function in base class being overloaded from child class"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 22 Mar 2005 11:09:01 -0500
"Andrey Tarasevich" <andreytarasevich@hotmail.com> wrote in message
news:ovCdnY5oI8YJ-KLfRVn-hg@comcast.com...
> modemer wrote:
> >> > Question is as in subject.
> >> >
> >> > For example:
> >> >
> >> > class BaseClass {
> >> > public:
> >> > void func() { do something; } // I don't want this function
> > being
> >> > overloaded in its inherited class
> >> > };
> >> >
> >> > class ChildClass : BaseClass {
> >> > public:
> >> > void func() { do otherthing; } // this should be inhibited when
> >> > compiling
> >> > }
> >>
> >> The 'ChildClass::func' does not overload 'BaseClass::func'. The 'func'
> >> name from the base class is _hidden_ by the derived class' member.
> >>
> >> Perhaps when you learn how things work, you won't need the "prevention"
> >> you ask about. What particular problem do you think you're going to
> >> solve by preventing what you call "overloading"?
> >> ...
> > Let me say this question in another way. Suppose I am a base class
designer,
> > I believe my func() in base class is the best solution for certain goal.
> > This base class is going to be used by other programmers, they are just
> > allowed to create their own child class inherated from my base class,
but I
> > don't want to write any email notice to say "func() is reserved for base
> > class, don't use it in your derived class, otherwise base::func() will
never
> > be called when child::func() is called", I want to know how to let
compiler
> > raise an error when the programmer happened defines func() in his child
> > class.
>
> There's one thing that is not clear in your question. There are several
> details in your posts that seem to suggest that in the real code the
> base class' function is virtual. In the code sample above the function
> is not virtual. Several people here missed this important fact and gave
> you answers that apply to virtual functions only, and, surprisingly, you
> didn't object. Can you, please, clarify whether the function you are
> talking about is virtual or not?
>
> --
> Best regards,
> Andrey Tarasevich
Thanks for pointing out the key word "virtual". Actually in this question,
virtual or not is not important because my object is to prevent *specific*
function(not all functions) in base class being defined in derived class no
matter it's virtual or not as long as there is a way to do, if derived class
happened defined(we have to believe that programmers have different
understandings about a system), C++ compiler should raise an error, but
unfortunately, nobody could answer this question directly, that means there
is not this kind of feature in C++.
When I studied C++, I noticed that C++ is trying the best to offer all
possibilities to control how member function of class is handled, like
private/protect/public/virtual/static/overload/override/namingConvention
etc. This is why I am looking for if there is a feature like the one
mentioned in my question. If this feature exists, I think the code or logic
would be more clear, simple or even easier on bug control, source code
maintain.
- Next message: Howard: "Re: Class to support keywords."
- Previous message: Jason Heyes: "Re: Class to support keywords."
- In reply to: Andrey Tarasevich: "Re: How to prevent a function in base class being overloaded from child class"
- Next in thread: David Harmon: "Re: How to prevent a function in base class being overloaded from child class"
- Reply: David Harmon: "Re: How to prevent a function in base class being overloaded from child class"
- Reply: Howard: "Re: How to prevent a function in base class being overloaded from child class"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|