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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:55:28+00:00 2026-06-14T14:55:28+00:00

So I am getting some weird behavior with some class hierarchy I am trying

  • 0

So I am getting some weird behavior with some class hierarchy I am trying to make.I am implementing graphs and I am doing it by making a Graph class that is will be implemented by AdjacencyMatrixGraph and AdjacencyListGraph so they could be used as a Graph by anything that wanted to use them.

I have one pure virtual function in Graph that get’s overwritten by the function in AdjacencyMatrixGraph, however I have a non virtual function of the same name, but different signature in Graph. I cannot call the non virtual method of the Graph class when accessing an AdjacencyMatrix class, but when I rename the non virtual method it works fine.

Like this:

When the classes look like this

class Graph
{
public:
   virtual void addVertex(Vertex vert, bool bidirectional)=0;
   void addVertex(unsigned int from, unsigned int to, double weight, bool bidirectional)
}

class AdjacencyMatrixGraph : public Graph
{
...
}




AdjacencyMatrixGraph test;
Vertex vert;
test.addVertex(vert,false);   //this statement compiles and works fine
test.addVertex(0,0,10.f,false)  //this statement fails to compile and says cadidates are addVertex(Vertex, bool)

However if I rename the non virtual method like so

class Graph
{
public:
   virtual void addVertex(Vertex vert, bool bidirectional)=0;
   void addVert(unsigned int from, unsigned int to, double weight, bool bidirectional)
}

AdjacencyMatrixGraph test;
Vertex vert;
test.addVertex(vert,false);   //this statement compiles and works fine
test.addVert(0,0,10.f,false)  //this statement compiles and works fine

This makes no sense to me because I thought the compiler sees addVertex(Vertex, bool) and addVertex(unsigned int,unsigned int, double, bool) as two completely different symbols. So one shouldn’t be overridden with inheritance, even if it would it shouldn’t be possible because the symbols take different arguments.

  • 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-14T14:55:30+00:00Added an answer on June 14, 2026 at 2:55 pm

    The definition in a derived class hides the base class overload declarations.

    To bring those into the scope of the derived class, use a using declaration, like

    using Graph::addVertex;
    

    in the derived class.

    By the way, this is a FAQ. It’s often a good idea to check the FAQ before asking. Or even just in general. 🙂

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

Sidebar

Related Questions

I'm getting some weird behavior from IE when trying to change a session variable
I have some weird behavior on the iPad that I am not getting on
I'm getting some behavior from the Text constructors that don't really make any sense.
We are getting some very weird behavior in Android. Our network stack (that talks
I'm can't figure out some weird behaviour that im getting in the rials console
I'm getting some weird behavior in asp.net MVC2 (at least it's not what I'm
I am getting some weird results while trying to pass a complex JSON object
I'm writing an IME (soft keyboard) and I'm getting some weird behavior from one
I'm getting some weird validation behavior: it's duplicating my validation error messages and I
I'm getting some weird behaviour recompiling some applications in 2009 that used widestrings at

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.