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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:30:03+00:00 2026-06-14T04:30:03+00:00

I have a superclass with a class defined inside it. like: class A {

  • 0

I have a superclass with a class defined inside it. like:

class A {
 public:
  class B {public: bool value;};

  A() {
      DoStuff(b_);
  }
  B b_;
 private:
  virtual void DoStuffImpl(B& b) = 0;
  void DoStuff(B& b) { return DoStuffImpl(b); }
};

class X : public A {
  // ...
 private:
  virtual void DoStuffImpl(B& b);
  void UseBForSomethingElse(B& b);
};

void X::DoStuffImpl(B& b) {
    UseBForSomethingElse(b);
}

void X::UseBForSomethingElse(B& b) {
    b.value = true;
}

int main(){
    X x;
    return x.b_.value;
}

My compiler seems to understand that DoStuffImpl() just fine. But, when I added UseBForSomethingElse(), the compiler could not find the definition for the B class. I tried to further specify by doing bool UseBForSomethingElse(A::B& b). This compiled, but then failed during linking.

How do I correctly specify the parent B, and why does it work for the virtual function but not the other one?

  • 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-14T04:30:04+00:00Added an answer on June 14, 2026 at 4:30 am

    Your updated post doesn’t properly qualify UseBForSomethingElse().

    void UseBForSomethingElse(const B& b)
    

    should be

    void X::UseBForSomethingElse(const B& b)
    

    Once this is fixed, you still have a problem (and heaven help me if I get this wrong).

    You’re firing a virtual method from a base class constructor without the derived class finishing construction. I.e, UseBForSomethingElse (non-virtual) is fired from DoStuffImpl() (virtual, pure @ A, defined in X) before X is finished base-construction (you’re, in fact in X’s base-construction when you make the call). This will trigger a ‘pure virtual function called’ since X’s vtable isn’t fixed up until its constructor is actually entered.

    This does happen on my machine as well, btw.

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

Sidebar

Related Questions

I have a class defined like so: public class AddRecordsToolbar<D extends IDataSource<T>, T extends
Within my code a have the following abstract superclass public abstract class AbstractClass<Type extends
I've defined a method in a class: public void setCollection(Collection<MyClass>); and in another class
I have a function defined in a superclass, InteractorStyle. Then I have another class
I have the following class defined as a bean: @Repository(userDao) public class UserDao extends
I have an AbstractEntity class as superclass for all my entites that defines an
I have a superclass we can call class A and few subclasses, e.g. class
Okay so, I have this project structure: package A.B class SuperClass (this class is
I have a class extends NamedParameterJdbcDaoSupport. well this superclass has a final setDataSource method
Since every class inherits the initializer from the superclass this is how I have

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.