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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:13:24+00:00 2026-05-16T09:13:24+00:00

This question is best described in code. I have a class called Vertex that

  • 0

This question is best described in code. I have a class called Vertex that contains an instance of a class called Params:

class Params {
    virtual Params operator + (Params const& p) = 0;
};

class Vertex {
    public:
        Params operator + (Params const& ap) const {
            return p + ap
        };

        virtual float eval() = 0;

    private:
        Params const p;
};

I also have a class called EllParams which is derived from Params and EllVertex which is derived from Vertex. What I’m wondering is how to deal with the private member variable p in Vertex in EllVertex: I want it to be of type EllParams. Is there some way of making p virtual/overriding it? Or should I look to templates for a solution?

  • 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-16T09:13:25+00:00Added an answer on May 16, 2026 at 9:13 am

    Well…you need to initialize the Params in Vertex somehow. So make it a parameter on the Vertex constructor. Then your EllVertex will pass an EllParams to the parent constructor from its constructor and that will be how the private Vertex.p is initialized.

    For example:

    class Params {
        virtual Params operator + (Params const& p) = 0;
    };
    
    class Vertex {
        public:
            Params operator + (Params const& ap) const {
                return *p + ap
            };
    
            virtual float eval() = 0;
    
        protected:
            Vertex(Params* inputParams) : p(inputParams) {}
    
        private:
            Params* const p;
    };
    

    Notice that I have changed your p member variable to a pointer. That way, you don’t have to ensure that a correct copy constructor is defined for Params or any subclasses.

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

Sidebar

Ask A Question

Stats

  • Questions 500k
  • Answers 500k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer right;5px; in #inner1 Syntax error. (the semicolon istead of colon) May 16, 2026 at 1:49 pm
  • Editorial Team
    Editorial Team added an answer You should really post your code(a), but here goes. Start… May 16, 2026 at 1:49 pm
  • Editorial Team
    Editorial Team added an answer The boilerplate code generated for case classes carries a small… May 16, 2026 at 1:49 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

This is best described in pseudo-code: class Thing {}; interface ThingGetter<T extends Thing> {
This problem is best described with an example. I have the following ClientBundle in
I have a question on the best way of exposing an asynchronous remote interface.
I have a question which is sonewhat more of a design question. I have
I want to do what's described in question 724043 , namely encode the path
I run a small blog network and on this I have a page where
We have a project that is starting to get large, and we need to
It is best to describe my question in an example: We create a Windows
UPDATE: Perhaps this wasn't clear from my original post, but I'm mainly interested in
In short: what is the best way to design and implement a factory+plugin mechanism,

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.