Qn on Restricting a public function overriding in base classes ?

How do we achieve the following :

Class Baseclass
{
    public:
        int  funXYZ();
    .....
};

Now, How do I modify the definition of the above class to restrict any other 
Class which derives from Baseclass, from over riding  public function 
funXYZ();
    Note that, the function funXYZ() needs to be public.
Is it possible ?


0
9/14/2005 12:11:53 PM
vc.mfc 33608 articles. 0 followers. Follow

7 Replies
632 Views

Similar Articles

[PageSpeed] 35

"satlal" <satish.lalam@gmail.com> skrev i meddelandet 
news:dg942b$67e$1@news.mch.sbs.de...
> How do we achieve the following :
>
> Class Baseclass
> {
>    public:
>        int  funXYZ();
>    .....
> };
>
> Now, How do I modify the definition of the above class to restrict 
> any other Class which derives from Baseclass, from over riding 
> public function funXYZ();
>    Note that, the function funXYZ() needs to be public.
> Is it possible ?
>

No. It doesn't matter if the function is public or not, a derived 
class can override any functions in the base class.

What are you trying to achive?


Bo Persson


0
bop (114)
9/14/2005 12:50:19 PM
It does matter for the function to be public,(or protected)...
If the function was private, ofcourse it is available only for that 
particular class, and cannot be overridden.

Well coming back to my original question,
I am lookin for a pattern to acheive this goal,
I have a baseclass implementation of funXYZ() , which wouldnt and shouldnt 
change.  I have to impose this restriction on my class definition so that no 
one else can override that function. But the base class functionality should 
be available for everyone to use.




"Bo Persson" <bop@gmb.dk> wrote in message 
news:ObiXdrSuFHA.2392@tk2msftngp13.phx.gbl...
>
> "satlal" <satish.lalam@gmail.com> skrev i meddelandet 
> news:dg942b$67e$1@news.mch.sbs.de...
>> How do we achieve the following :
>>
>> Class Baseclass
>> {
>>    public:
>>        int  funXYZ();
>>    .....
>> };
>>
>> Now, How do I modify the definition of the above class to restrict any 
>> other Class which derives from Baseclass, from over riding public 
>> function funXYZ();
>>    Note that, the function funXYZ() needs to be public.
>> Is it possible ?
>>
>
> No. It doesn't matter if the function is public or not, a derived class 
> can override any functions in the base class.
>
> What are you trying to achive?
>
>
> Bo Persson
>
> 


0
9/14/2005 1:24:02 PM
So dont make it virtual.

-- 
- Mark Randall
http://zetech.swehli.com

"Those people that think they know everything are a great annoyance to those 
of us who do"
    Isaac Asimov

"satlal" <satish.lalam@gmail.com> wrote in message 
news:dg989l$mhf$1@news.mch.sbs.de...
> It does matter for the function to be public,(or protected)...
> If the function was private, ofcourse it is available only for that 
> particular class, and cannot be overridden.
>
> Well coming back to my original question,
> I am lookin for a pattern to acheive this goal,
> I have a baseclass implementation of funXYZ() , which wouldnt and shouldnt 
> change.  I have to impose this restriction on my class definition so that 
> no one else can override that function. But the base class functionality 
> should be available for everyone to use.
>
>
>
>
> "Bo Persson" <bop@gmb.dk> wrote in message 
> news:ObiXdrSuFHA.2392@tk2msftngp13.phx.gbl...
>>
>> "satlal" <satish.lalam@gmail.com> skrev i meddelandet 
>> news:dg942b$67e$1@news.mch.sbs.de...
>>> How do we achieve the following :
>>>
>>> Class Baseclass
>>> {
>>>    public:
>>>        int  funXYZ();
>>>    .....
>>> };
>>>
>>> Now, How do I modify the definition of the above class to restrict any 
>>> other Class which derives from Baseclass, from over riding public 
>>> function funXYZ();
>>>    Note that, the function funXYZ() needs to be public.
>>> Is it possible ?
>>>
>>
>> No. It doesn't matter if the function is public or not, a derived class 
>> can override any functions in the base class.
>>
>> What are you trying to achive?
>>
>>
>> Bo Persson
>>
>>
>
> 


0
yr (150)
9/14/2005 1:48:21 PM
satlal,

   I think you're confused.  Making a function within a class "private"
means that it cannot be INHERITED, not that it can't be OVERRIDDEN.
That is, no one who derives from your class will be able to use your
funxyz, but they can certainly still write their own.  For instance,
the following program:

class A {
    public:
        void someotherfunc(void);
    private:
        void funxyz(void);
};

class B : public A {
    public:
        void funxyz(void);
};

void A::someotherfunc(void) {
    printf("This is A's someotherfunc\n");
    funxyz();
}

void A::funxyz(void) {
    printf("This is A's funxyz\n");
}

void B::funxyz(void) {
    printf("This is B's funxyz\n");
}

void main(void) {
    A a;
    B b;
    A.someotherfunc();
    B.funxyz();
}


will produce the output:

This is A's someotherfunc
This is A's funxyz
This is B's funxyz

0
9/14/2005 3:01:36 PM
Other than the fact that your requirement is inconsistent with the design of the C++
language there's nothing wrong with it.

While one can argue about whether or not a function should be overridden, there is no
syntax in C++ for preventing this for public members, and therefore there is no way to
prevent it from being overridden.

Personally, I find the concept of forbidding override (such as Java incorporates) as being
completely counterproductive; it prohibits the client of the class from extending the
class in any meaningful way. It allows the creator of the class to make claims of
perfection that strike me as unfounded. 

Key question: so what if someone overrides your function? If they do so incorrectly, they
have an erroneous program, and if it doesn't work, it is their problem, not yours.

And if anyone comes up with some elaborate scheme to prevent override, it can be trivially
defeated, so the concept isn't particularly relevant.  That's why Java's notion of a
terminal method that cannot be overridden is foolish.  All I need is a wrapper class to
defeat it, so why make my life inconvenient?
					joe

On Wed, 14 Sep 2005 18:54:02 +0530, "satlal" <satish.lalam@gmail.com> wrote:

>It does matter for the function to be public,(or protected)...
>If the function was private, ofcourse it is available only for that 
>particular class, and cannot be overridden.
>
>Well coming back to my original question,
>I am lookin for a pattern to acheive this goal,
>I have a baseclass implementation of funXYZ() , which wouldnt and shouldnt 
>change.  I have to impose this restriction on my class definition so that no 
>one else can override that function. But the base class functionality should 
>be available for everyone to use.
>
>
>
>
>"Bo Persson" <bop@gmb.dk> wrote in message 
>news:ObiXdrSuFHA.2392@tk2msftngp13.phx.gbl...
>>
>> "satlal" <satish.lalam@gmail.com> skrev i meddelandet 
>> news:dg942b$67e$1@news.mch.sbs.de...
>>> How do we achieve the following :
>>>
>>> Class Baseclass
>>> {
>>>    public:
>>>        int  funXYZ();
>>>    .....
>>> };
>>>
>>> Now, How do I modify the definition of the above class to restrict any 
>>> other Class which derives from Baseclass, from over riding public 
>>> function funXYZ();
>>>    Note that, the function funXYZ() needs to be public.
>>> Is it possible ?
>>>
>>
>> No. It doesn't matter if the function is public or not, a derived class 
>> can override any functions in the base class.
>>
>> What are you trying to achive?
>>
>>
>> Bo Persson
>>
>> 
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
9/14/2005 3:38:17 PM
Sorry, ignore this - getting my languages mixed up.

Appologies *doh and all that*

-- 
- Mark Randall
http://zetech.swehli.com

"Those people that think they know everything are a great annoyance to those 
of us who do"
    Isaac Asimov

"Mark Randall" <mark[__OKTHISISFAKE_]yr@REMOVETHISgoogle.ANDTHIScom> wrote 
in message news:%231qy6LTuFHA.2504@tk2msftngp13.phx.gbl...
> So dont make it virtual.
>
> -- 
> - Mark Randall
> http://zetech.swehli.com
>
> "Those people that think they know everything are a great annoyance to 
> those of us who do"
>    Isaac Asimov
>
> "satlal" <satish.lalam@gmail.com> wrote in message 
> news:dg989l$mhf$1@news.mch.sbs.de...
>> It does matter for the function to be public,(or protected)...
>> If the function was private, ofcourse it is available only for that 
>> particular class, and cannot be overridden.
>>
>> Well coming back to my original question,
>> I am lookin for a pattern to acheive this goal,
>> I have a baseclass implementation of funXYZ() , which wouldnt and 
>> shouldnt change.  I have to impose this restriction on my class 
>> definition so that no one else can override that function. But the base 
>> class functionality should be available for everyone to use.
>>
>>
>>
>>
>> "Bo Persson" <bop@gmb.dk> wrote in message 
>> news:ObiXdrSuFHA.2392@tk2msftngp13.phx.gbl...
>>>
>>> "satlal" <satish.lalam@gmail.com> skrev i meddelandet 
>>> news:dg942b$67e$1@news.mch.sbs.de...
>>>> How do we achieve the following :
>>>>
>>>> Class Baseclass
>>>> {
>>>>    public:
>>>>        int  funXYZ();
>>>>    .....
>>>> };
>>>>
>>>> Now, How do I modify the definition of the above class to restrict any 
>>>> other Class which derives from Baseclass, from over riding public 
>>>> function funXYZ();
>>>>    Note that, the function funXYZ() needs to be public.
>>>> Is it possible ?
>>>>
>>>
>>> No. It doesn't matter if the function is public or not, a derived class 
>>> can override any functions in the base class.
>>>
>>> What are you trying to achive?
>>>
>>>
>>> Bo Persson
>>>
>>>
>>
>>
>
> 


0
yr (150)
9/14/2005 9:24:52 PM
You are right Daniel, My mistake
Thanks


"Jay Daniel" <Phaze426SPAMBOX@gmail.com> wrote in message 
news:1126706997.204153.143900@g44g2000cwa.googlegroups.com...
> satlal,
>
>   I think you're confused.  Making a function within a class "private"
> means that it cannot be INHERITED, not that it can't be OVERRIDDEN.
> That is, no one who derives from your class will be able to use your
> funxyz, but they can certainly still write their own.  For instance,
> the following program:
>
> class A {
>    public:
>        void someotherfunc(void);
>    private:
>        void funxyz(void);
> };
>
> class B : public A {
>    public:
>        void funxyz(void);
> };
>
> void A::someotherfunc(void) {
>    printf("This is A's someotherfunc\n");
>    funxyz();
> }
>
> void A::funxyz(void) {
>    printf("This is A's funxyz\n");
> }
>
> void B::funxyz(void) {
>    printf("This is B's funxyz\n");
> }
>
> void main(void) {
>    A a;
>    B b;
>    A.someotherfunc();
>    B.funxyz();
> }
>
>
> will produce the output:
>
> This is A's someotherfunc
> This is A's funxyz
> This is B's funxyz
> 


0
9/15/2005 7:34:19 AM
Reply:

Similar Artilces:

M2005 Error on log in
I recently upgraded from Money 2003 to 2005 Premium on a Windows 2000 machine. Logon is always full of trials and tribulations. Sometimes it does not recognize my .net password. Today it's giving me a message "The place you are trying to reach only functions in the Business version of Money, and can't be used in the version you are using now. If you want to use this place you will have to upgrade to Money Small Business." If I click "OK" it returns to the logon screen. If I try to login again I get the same message and I cannot log in "offline." ...

Print a report from a form based on a query
I have a form that I enter a parameter and run a query which pulls anywhere from 1-???? records. After these records are displayed, I have the option of printing them (as a report) from a print command button which I can't get to work. My form has a header with an Equip code and multiple detail lines. This code is passed to a query which would run and pull my data again as the report has more data in the online form. My problem is that this isn't getting to the report. Am I making this more complicated than it has to be. On Fri, 14 May 2010 12:57:01 -0700, Mommybear ...

intermittent access to public folders PLEASE READ!!
I have about ten users that cannot access one public folder tree off and on. They can access all other folders without error. The folder is a third level folder, and all permissions are set at the root. Both Default and Anonyms have contributor permission all the way down the tree. If I add the users directly to the fold they gain access for a few hours, then they cannot access again. There is a 1000 users in the enterprise, and everyone else is not having any problems. ANY IDEAS would be great. How many servers you have? If there are several it might be replication problem. Or ...

Public folder calendar reminders?
Anyone using any third party products that allow multiple users to get either email (preferred) or pop-up reminders of specific appointments on public folder calendars? Ideally, I'd like a user to be able to set up an appointment on a pf calendar, and specify users to be notified when that appointment is getting close, rather than sending out a meeting request and having individual users hold the appointments on each of their calendars. Have looked briefly at Important Dates + by Infoware (http://www.infoware.ca/content/infoframe.htm?imprtdat.asp) but hate implementing 3rd party s...

Conditional Formatting based on deadlines
I'm trying to change the colour of rows based on how close the deadlin is. The deadline date is in column E I've been trying =IF $E2<DATE+7 So, if the date in E2 is 7 days away or less, then apply conditiona formatting. Excel won't accept this, though. Any ideas -- madblok ----------------------------------------------------------------------- madbloke's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1442 View this thread: http://www.excelforum.com/showthread.php?threadid=27448 Under conditional formatting set condition 1 Formula is =+$...

I'd like to conditionally format a cell based on today's date
I have a column that contains important dates, and I'd like to say make the forecolor red if they're 3 months away, blue if their 6 months away, etc... How do I do this? Look up "conditional formatting" in Excel help. -- David Biddulph "0to60" <holeshot60_nospam@yahoo.com> wrote in message news:%23mzT42nAJHA.4052@TK2MSFTNGP06.phx.gbl... >I have a column that contains important dates, and I'd like to say make the >forecolor red if they're 3 months away, blue if their 6 months away, etc... > > How do I do this? On Aug 20, 2:32=A0...

2000 to 2003 Migration
I am running Exchange 2000 SP3a in production. I have built another box that is running Exchange 2003 SP2 that I am planning to migrate to in the next few weeks. I have set up replication by using Microsoft's recommendations at http://support.microsoft.com/default.aspx?scid=kb;en-us;307917&Product=exch2k. When I check the replication status, the E2K3 box shows "Local Modified". When I check the public folder instances on the new server, the folders do not seem to have replicated to it. Am I missing something? "millh0use" <jeremy.miller@fazolis.com> wrot...

Saving publications
can anyone tell me why when I save a publication and close it down, when I next open it the presentation of text and pictures has changed? Even the font changes back to Times New Roman! Any help please? Chris you are awfully talented and suggest you have powers of a witch. What you describe is an issue of witch craft and not Windows or Publisher. -- "If you don't know where you are going, any road will take you there!" Hi Chris (anonymous@discussions.microsoft.com), in the newsgroups you posted: || can anyone tell me why when I save a publication and close it down, ||...

Public Folders and Permission Problems
Why did my original question get deleted? Hello, I need a damn answer! This is driving me up, around, about, and through several walls... I just don't understand it. I create a new account, setup an exchange mailbox with it, setup the user AS an administrator... I logon to the server via Microsoft Outlook from a client computer AS the account I just made... it verifies it... I see the Public Folder...I go to expand the Public Folder...and I see Favorites and All Public Folders... I go to expand All Public Folders, I see Internet Newsgroups.. a giant gray preview pane says: ...

I'm New to VB, I wish to Pass 2 strs to a VB Function
Greetings, I am new to VB, but have recently found scripting interesting. If possible, I would like to seek your indulgence... I found a really nice code snippet at http://kandkconsulting.tripod.com/VB/VBTips.htm The site states: "If you've ever written an application that stores passwords, you'll know the importance of encryption. There's no point in password protecting things if all a user has to do is open a file or database to get all of the stored passwords. It is possible, however, to write a very simple function that will both encrypt and decry...

Help Please
> This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --B_3345217232_16739679 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit I use Entourage 2008 on an Exchange 2003 server. When I enter a meeting request/calendar event on a calendar contained in a public folder on the system, the event requests are repeatedly emailed to the calendar administrator. How can I make this stop? --B_3345217232_16739679 Content-type: text/html; charset="US-ASCII"...

Unable to see public folder in OWA
I need help! We're in the middle of migrating our exchange servers from exchange 2000 to 2003. Everything is working fine except, I noticed one particular important public folder (calendar item) could not be displayed in OWA...I can see other public folders in OWA just fine. When I log in using Outlook 2003, I can see this folder just fine, but in OWA it says "Page cannot be displayed". Can someone tell me where I could start looking for this folder, and how I might be able to get it to show up in OWA? By the way, the user who needs this folder claims she just noticed thi...

Date & Time Detention Clock Functions
Hi I am creating a sheet that acts as a production clock and works out various factors that can change for work. I need help in several areas the production item has two clocks running simultaneously and as I cannot post my sheet I will try to explain what I mean. Product item I will call X X arrives say at 13:00 hrs today it has to be out within 24 hrs exactly I need a cell to add on 24 hours which shows the date and time known as Relevant Out date / time. During the 24 hours X may be transferred to another facility so I have to show that X is transfers out (I enter this cell with...

How can I apply holidays to a public calendar?
We have a shared office calendar to which I post staff vacations, office closed days, etc. (I'm the administrator). I can't get holidays applied to that calendar. Any ideas? Thanks, Mary Apply them to your own Calendar and then switch your view to By Category. you can now easily copy or move the Holiday entries to the Public Folder. -- Robert Sparnaaij [MVP-Outlook] Coauthor, Configuring Microsoft Outlook 2003 http://www.howto-outlook.com/ Outlook FAQ, HowTo, Downloads, Add-Ins and more http://www.msoutlook.info/ Real World Questions, Real World Answers ----...

Change Range In COUNTIF Formula Based On Value In A Cell
Hopefully I can make this clear. I have a formula in which I have to change the range in which I am performing a COUNTIF. Here's the formula. =(COUNTIF($J8:$J28,"A"))+(COUNTIF($J8:$J28,"C")) Essentially what I am doing is copying this formula down the worksheet. What it is doing is looking at the next 21 line items and counting how many are equal to A or C. That part works fine and I've got everything going great. Problem is, I want to dynamically change the number of line items I perform the lookup on. Essentially I want to have cell A1 contain a value that...

Lookup record in subform based on combo im main form
I''d like to lookup a record in a subform based on a combo box in the main form. In the afterupdate event of the combo box I like to lookup and display the record in the subform. Not sure how to do this. Thanks for your help. Here's what I have now: Private Sub Combo116_AfterUpdate() Dim lngID As Long lngID = Combo116 Form![frmBookingShowsAssociations].SetFocus DoCmd.GoToControl "txtID" Form![txtID].SetFocus '************* 'At this point it says "Can't find the field 'txtID' referred to in your expression. '****...

Unable to set the Text Property of the Characters class
I have the following code in a VB6 program: Function BoldMarkup(R As Range) As String Dim N As Long Dim S As String Dim InBold As Boolean If R.Cells.Count > 1 Then Exit Function End If If R.HasFormula = True Then Exit Function End If If Len(R.Text) = 0 Then Exit Function End If If Len(R.Text) = 1 Then If R.Characters(1, 1).Font.Bold Then BoldMarkup = "<b>" & R.Text & "</b>" Exit Function End If End If For N = 1 To Len(R.Text) If R.Characters(N, 1).Font.Bold = True Then If InBold = False Then S = S & "<b>...

How can I use the format function to change the stored value of a cell in excel?
How can I use the format function to change the stored value of a cel in excel? For example, In a colum I have data that is displayed like this: 19:59 12/31/69 But the actual stored data when you go to edit the cell is like this: 12/31/1969 7:59:00 PM I want the stored data to be like the displayed value so I can sort th column by the time and not the day. By the way, I do not know how to do macros or use VB.: -- Message posted from http://www.ExcelForum.com Hi you can search by date and time. No problem with this display. what are you exactly looking for -- Regards Frank Kabel Frankf...

IIf function for 3 possible outcomes?
I want to calculate a rate for 3 types of Gears (coded "OT04S", "OT16S", and "POT02S". I've used IIf in the past when the database contained only 2 Gear types, but can't seem to get the expression correct now that there are 3 Gear types. Can I use the IIf function here or should I be going in another direction? Here's my best attempt at a 3-outcome IIf: 'Rate: IIf([Gear]="OT04S",([Count]/([Distance]*"2.93")),(IIf([Gear]="OT16S",([Count]/([Distance]*"3.11"))),([Count]/([Distance]*"1.75"))))'...

Using atl based win dll with CString functions from the mfc projec
I have atl based general windows dll with class which contains functions which uses CString as parameters or return values. This dll might be used from the atl or mfc project. Dll can be used from ATL project without problems but whenever I try to use this class from the MFC project I get the following linker errors: error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __thiscall MyClass::AddMenu(long,class ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &,long)" ... If I replace CStri...

Public Folder Permissions
I'm having a frustrating problem with an Exchange 2000 server. The clients can't create or delete folders or the items in them. Even as as a user in the Domain Admin group, I can't create or delete items. I've set permissions on the public folders to allow EVERYONE Full Control and it still isn't letting me do anything unless I am logged on with the Administrator account. Any help is appreciated. Any help from http://support.microsoft.com/default.aspx?scid=kb;en-us;313866 If not, do you get an error message? P.S. Domain admins do not necessarily have any particular ...

Copying Data Down the Column But Only Based on What's in Column A
Hello: I have four columns in an Excel spreadsheet. Column A ("Item Number") is a list of inventory items. Column B ("Location Code") is to contain the phrase "CH" in each cell of column B. Column C ("Order Point Qty") contains quantities in each cell of column C. Column D ("Number of Days") contains the number "10" in each cell of column D. At the end of this posting is VBA code for a macro in Excel's Visual Basic Editor that I am using to essentially create this spreadsheet. I am having trouble with the fo...

email address tab missing from Public Folder properties
When I create a new Public Folder, I don't see the email address tab in the properties panel. Existing folders show General Replication Limits Exchange General E-mail Addresses Exchange Advanced Details Permissions Member Of but new folders only show General Replication Limits Details Permissions How do I fix this? Thanks! -- Jim "Jim Elden" <x@yz> wrote: >When I create a new Public Folder, I don't see the email address tab in the >properties panel. Existing folders show > >General >Replication >Limits >Exchange General >E-mail Addres...

Conditional Formatting based on match to external list
Hi, I have a list of companies, need to look at a separate list of countries and, if any of the companies are in countries found in that list, I want to highlight the cell containing the company country value. Basically, I need a formula that looks at the company country value, then searches the entire list of countries to find a match. I've got over 10,000 companies in one list and 100+ countries in the second list. Dawn untested, assumes your list of countries is called "countries" and the company countries column is E. =match($E1,countries,0) ...

Subject: send to mail recipient function in windows 2003 server / outlook 2003
I have just recently noticed that on the new servers that I am building, running windows 2003 server and outlook 2003 and terminal services, the "Send To Mail Recipient" option doesn't work. Everything appears normal, but when I click on the icon nothing happens. I have attempted to run "REGSVR32 SENDMAIL.DLL" and have checked the registry for the proper keys. I have never experienced this problem with previous versions of the OS or Office and I'm surprised I haven't found any other posts similar to this. Please help. How did you install Office 2003 on the Term...