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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:13:13+00:00 2026-05-30T05:13:13+00:00

Just recently learned the correct application of inheritance of classes in Java and thought

  • 0

Just recently learned the correct application of inheritance of classes in Java and thought to apply it to some code I’m writing in C++.

The following is a header for an empty Node.cpp:

#ifndef Node_h
#define Node_h

#include <string>

using namespace std;

///////////////////////////////////////////////////////
//Class Declarations
class Array;
class Hash;
class Node;
    class BodyNode;
        class RealNode;
            class CharNode;
            class ComboNode;
        class EndNode;
    class HashNode;
    class NodeFollower;

///////////////////////////////////////////////////////
//Class Definitions
class Node{
public:
    virtual string toString(int info) = 0;
    };

class BodyNode: public Node{
public:
    };

class RealNode: public BodyNode{
protected:
    Hash *wordHash, *addressHash;
    Array *followers;
    int count;

//Initialization
    RealNode();
    ~RealNode();

//Hashes
    BodyNode getNext(int address);
    NodeFollower getWord(BodyNode *word);
    NodeFollower getAddress(int address);

    string toString(int info);
    };

#endif

From this code, I get the following error:

Node.h:43:11: error: invalid abstract return type for member function ‘BodyNode RealNode::getNext(int)’
Node.h:28:7: note:   because the following virtual functions are pure within ‘BodyNode’:
Node.h:25:17: note:     virtual std::string Node::toString(int)

Looked this up all over google, stackoverflow, and cplusplus, and while I find a lot of answers that surround this concern, I couldn’t find the exact answer that I needed to fix it. The cplusplus.com site that I was sourcing from is:

http://www.cplusplus.com/doc/tutorial/polymorphism/

Additionally, a few of the answers I found on stackoverflow indicated that

using namespace std;

is to be avoided, and it sounds like for good reason, but I can’t figure out how to include string. I tried

string::string

for each declaration, and I tried

using namespace std::string;

but both were to no avail. Thank you in advance for the help!

  • 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-30T05:13:15+00:00Added an answer on May 30, 2026 at 5:13 am

    Your first problem is that BodyNode inherits from regular Node which has a toString() pure-virtual function. If it’s pure-virtual (the =0) then you MUST provide a definition for it in all derived classes, and you have not.

    So, since you have not provided the pure-virtual function definition within BodyNode, it is also an abstract class and uninstantiable (an abstract-class has 1 or more pure-virtual methods so it cannot be instantiated).

    You also have an issue that getNext() returns a BodyNode type, and since BodyNode is abstract, this isn’t possible – you COULD return a pointer to it instead of a by-copy-value, but I think your real problem is that it shouldn’t be abstract in the first place.

    Provide a default toString() function in BodyNode to fix your problem.

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

Sidebar

Related Questions

I recently learned that Unicode is permitted within Java source code not only as
I just recently learned about the Properties class in java, and I'm trying to
I've just recently learned the PureMVC framework, and am a little confused as to
We just recently migrated our web application from .NET 1.1 to .NET 2.0. The
I just recently started diving into Real World Haskell and the book provides some
I just recently learned about Scope Guard C++ idiom. Unfortunately I can't find any
I started working in Python just recently and haven't fully learned all the nuts
I've recently started learning C#. I just learned about properties and decided to make
I've only just recently learned about Google's programming language, Go. I've been intrigued by
I've just recently learned how jquery can access dynamically generated content, by placing a

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.