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

  • SEARCH
  • Home
  • 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 3391596
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:49:14+00:00 2026-05-18T03:49:14+00:00

I have the following classes: class A { public: virtual void f() {} };

  • 0

I have the following classes:

class A {
public:
    virtual void f() {}
};


class B : public A{
public:
    void f(int x) {}
};

If I say

B *b = new B();
b->f();

the compiler says error C2660: ‘B::f’ : function does not take 0 arguments.
Shouldn’t the function in B overload it, since it is a virtual function? Do virtual functions get hidden like this?

EDIT: I indeed meant to inherit B from A, which shows the same behaviour.

  • 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-18T03:49:15+00:00Added an answer on May 18, 2026 at 3:49 am

    Assuming you intended B to derive from A:

    f(int) and f() are different signatures, hence different functions.

    You can override a virtual function with a function that has a compatible signature, which means either an identical signature, or one in which the return type is “more specific” (this is covariance).

    Otherwise, your derived class function hides the virtual function, just like any other case where a derived class declares functions with the same name as base class functions. You can put using A::f; in class B to unhide the name

    Alternatively you can call it as (static_cast<A*>(b))->f();, or as b->A::f();. The difference is that if B actually does override f(), then the former calls the override, whereas the latter calls the function in A regardless.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following classes: class A { public: virtual void myfunc(unsigned char c,
I have the following existing classes: class Gaussian { public: virtual Vector get_mean() =
I have the following hierarchy of classes class classOne { virtual void abstractMethod() =
I have the fallowing classes: class CpuUsage { public: CpuUsage(); virtual ~CpuUsage(); void SetCpuTotalTime(CpuCore
If i have the following classes public class Order { public virtual ISet<OrderItem> OrderItems
I have following classes. class A { public: void fun(); } class B: public
Say I have the following abstract class: class AbstractClass { public: AbstractClass() {} virtual
i have the following classes: class A { protected: A *inner; public: .... virtual
I have the following Entity Framework POCO classes: public class Customer { public int
I have the following classes class Parent { virtual void doStuff() = 0; };

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.