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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:57:53+00:00 2026-06-05T21:57:53+00:00

I have two (unrelated) classes. The first one is Point: typedef std::complex<double> complex_number; class

  • 0

I have two (unrelated) classes. The first one is “Point”:

typedef std::complex<double> complex_number;

class Point
{
public:
    Point(const complex_number &affix);

    const complex_number & get_affix() const;
    void set_affix(const complex_number & new_affix);

    // etc
private:
    complex_number affix_;
};

(By the way, sorry for asking this unrelated question, but where is the right place to put my type definitions? Is here, top of my point.hpp file, “good practice”?)

The second one is “Abstract_Vertex” (this is meant to be part of an abstract graph later):

typedef int vertex_label;

class Abstract_Vertex
{
public:
    Abstract_Vertex(const vertex_label &label);

    const vertex_label & get_label() const;
    const vertex_label & get_neighbor_label(const int &index) const;
    void set_label(const vertex_label &new_label);

    bool is_neighbor_label(const vertex_label &label) const;

    // etc
protected:
    vertex_label label_;
    std::vector<vertex_label> neighbor_labels_;
};

Now I want to create a third class, “Plane_Vertex” (a vertex located somewhere in the plane). I am pondering two ways to do that :

  1. Multiple inheritance : the Plane_Vertex class inherits from both Point and Vertex, and does not have any members

  2. the Plane_Vertex class only inherits from Vertex and has a private Point point_ member.

Of course I could easily avoid multiple inheritance and just go for option 2., but I am a good little conscientious C++ learner and I want to know what “good practice” would be in my situation.

Thank you for your insights!

  • 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-05T21:57:55+00:00Added an answer on June 5, 2026 at 9:57 pm

    There could be a third option. You can do as the standard library does, and make the AbstractVertex a template. You can then implement the graph navigation, and generic functionality in the template, and let the user provide the values to store in the nodes as a template argument.

    Because design is compromising, I am going to point out the main differences from my point of view.

    Related/Unrelated vertex types

    In the template approach, different instantiations are completely different types. That means that Vertex<int> and Vertex<Point> are not related. On the other side, in the polymorphic approach above all vertices IntVertex, PointVertex… are AbstractVertex objects: You can combine them in containers and connect them or use them interchangeably in code that can use AbstractVertex. Whether this is a limitation or an advantage of either approach is, again, a design decision. I prefer the types to be unrelated, as I don’t feel that you should mix those types.

    Amount of code to write

    In the template approach you implement the template and then you just instantiate, in the polymorphic approach you need to provide a new class for each possible element that you want to include in a graph

    If at the end you decide to go for the polymorphic approach (I wouldn’t), then I would avoid using multiple inheritance from both types, and prefer composition. In general, inheritance is probably the most abused feature of object oriented languages, it can be used to solve many problems, and sometimes it seems like the easiest solution to all, but it is not. In particular neither of your base types seem to be designed for inheritance, there is no functionality to be overridden by derived types, no virtual functions. These are clear indications that you are abusing inheritance where composition suffices.

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

Sidebar

Related Questions

OK, so I have two (completely unrelated, different project) classes using iterators now. One
I have two unrelated repositories 'public' and 'develop': prj/ public/ develop/ 'develop' has lots
I currently have two unrelated MVC3 projects hosted online. One works fine, the other
I have used EF to generate classes for my database tables: public partial class
I have two unrelated (not sharing any ancestor check in) Git repositories, one is
Have two actionsheet buttons and one modalviewcontroller on mainviewcontroller in application. Now for two
I have two DropDownListBoxes one is called ddlDay and the other is ddlMonth. As
I have two classes generated by LINQ2SQL both from the same table so they
I have two MXML component files and try to work with them as classes.
I have two simple interfaces: public interface HasId<ID extends Serializable> extends Serializable { T

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.