Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 794803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:22:23+00:00 2026-05-14T22:22:23+00:00

Okay, so I’m trying to override a function in a parent class, and getting

  • 0

Okay, so I’m trying to override a function in a parent class, and getting some errors. here’s a test case

#include <iostream>
using namespace std; 

class A{
public:
    int aba;
    void printAba();
};

class B: public A{
    public:
    void printAba() new;
};

void A::printAba(){
    cout << "aba1" << endl;
}

void B::printAba() new{
    cout << "aba2" << endl;
}

int main(){
    A a = B();

    a.printAba();

    return 0;
}

And here’s the errors I’m getting:

Error   1   error C3662: 'B::printAba' : override specifier 'new' only allowed on member functions of managed classes   c:\users\test\test\test.cpp 12  test
Error   2   error C2723: 'B::printAba' : 'new' storage-class specifier illegal on function definition   c:\users\test\test\test.cpp 19  test

How the heck do I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T22:22:24+00:00Added an answer on May 14, 2026 at 10:22 pm

    There’s no need to put any keywords in the derived class to override a function.

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

    But the base class’s method should be virtual, to allow the method be selected depending on the actual identity of the variable.

    class A{
    public:
        int aba;
        virtual void printAba();
    };
    

    And if you create an B on stack and copy into A, slicing would occur. You should create a B on heap and cast the pointer as A.

    A* a = new B();
    a->printAba();  // if printAba is not virtual, A::printAba will be called.
    delete a;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, not sure what I'm doing here, other than it's not right. Trying to
Okay, I'm having some serious issues here. I'm new to this site, and new
Okay, I'm trying to make a quick little class to work as a sort
Okay, so I'm running a small test webserver on my private network. I've got
Okay so im working on this php image upload system but for some reason
Okay, here's the scenario. I have a utility that processes tons of records, and
Okay, I might confuse some people who might be able to answer this question,
okay code: #!/usr/bin/python import wx import sys class XPinst(wx.App): def __init__(self, redirect=False, filename=None): wx.App.__init__(self,
Okay. I have this code on my site: <?php session_start(); include database.php; include bruger.php;
Okay, so I'm trying to create a list of he folders, and sub-folders and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.