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 9079763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:54:47+00:00 2026-06-16T19:54:47+00:00

Very new to c++ having trouble calling a function from another class. Class B

  • 0

Very new to c++ having trouble calling a function from another class.

Class B inherits from Class A, and I want class A to be able to call a function created in class B.

using namespace std;

class B;

class A 
{

public:

    void CallFunction ()
    {
        B b;
        b.bFunction();
    }

};

class B: public A
{
public:
    virtual void bFunction()
        {
            //stuff done here
        }

};

It all looks fine on screen (no obvious errors) but when I try to compile it i get an error C2079 ‘b’ uses undefined class B.

I’ve tried making them pointers/ friends but I’m getting the same error.

  • 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-06-16T19:54:48+00:00Added an answer on June 16, 2026 at 7:54 pm
        void CallFunction ()
        {   // <----- At this point the compiler knows
            //        nothing about the members of B.
            B b;
            b.bFunction();
        }
    

    This happens for the same reason that functions in C cannot call each other without at least one of them being declared as a function prototype.

    To fix this issue we need to make sure both classes are declared before they are used. We separate the declaration from the definition. This MSDN article explains in more detail about the declarations and definitions.

    class A
    {
    public:
        void CallFunction ();
    };
    
    class B: public A
    {
    public:
        virtual void bFunction()
        { ... }
    };
    
    void A::CallFunction ()
    {
        B b;
        b.bFunction();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very new to using MySql and am having trouble retrieving values from my
I'm very new to Rails (and Ruby), and am having trouble installing and using
I'm very new to JavaScript in general so having trouble with this. Working with
I'm very new to Sql, and having trouble wrapping my brain around the syntax.
I am very new to Classic ASP and Visual Basic. I am having trouble
I'm very new to JQuery, and I'm having some trouble understanding how to do
I'm very new to lambda expressions in C#, and I'm having trouble conceptualizing how
I'm having trouble submitting some hidden form data via post from the following function:
I am very new To EntityFramework and having trouble to understand why first code
Hello friends I am having trouble getting desired results using str_replace (); function of

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.