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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:43:11+00:00 2026-05-28T03:43:11+00:00

I have the following abstract class class Language { const std::string name ; protected:

  • 0

I have the following abstract class

class Language {
    const std::string name ;

    protected:
    std::string cmd, home ;
    Config::Section cfg ;

    bool load_conf() {
        home = env("HOME") ;

        // DEBUG
        std::cout << home << std::endl ;
        std::cout << name << std::endl ;

        if (!cfg.load(home + "/.cr", name)) {
            std::cerr << "cr: No configuration found for this language." << std::endl ;
            return false ;
        }

        return true ;
    }

    public:        
    virtual bool handles(const std::string) = 0 ;
    virtual int run(std::string) = 0 ;
} ;

And a number of derived classes, like this, which implement it

class Python : public Language {
    const std::string name ;

    public:
    Python() : name("python") {}

    bool handles(const std::string) ;
    int run(std::string) ;
};

The problem I’m having is in load_conf() where for some reason name is reported to be empty, which makes it spit out an error even though the configuration is fine. load_conf() is called from run() which is implemented by each derived class.

I’ve tried making name protected and public, but neither seems to make any difference. Ideally I’d like to only declare name in the abstract class (as protected) and not have to repeat the declaration in each derived class, but when I try that it won’t compile. I’ve also tried using this->name but that’s also empty, and removing the const also makes no difference.

I get the feeling it’s a scoping issue, but what am I missing?

  • 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-28T03:43:12+00:00Added an answer on May 28, 2026 at 3:43 am

    Declare a constructor in your base class which accepts a single argument, the value to intialize name to and pass that in the derived ctors.

    here is an example:

    class Language {
        const std::string name ;
    };
    
    class Python : public Language {
        const std::string name ; // <-- this is different, and frankly redundant
    };
    

    Something like the following should replace the above…

    class Language {
        const std::string name ;
        Language(std::string some_name) : name(some_name) {}  // <-- set the name
    };
    
    class Python : public Language {
        Python() : Language("python") {} // construct the base with the name...
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following classes: abstract class Transport{ protected String name; protected Transport(String name){
Lets say I have the following code: abstract class Animal case class Dog(name:String) extends
I have the following class: public abstract class TableServiceEntity { protected TableServiceEntity(); protected TableServiceEntity(string
Lets assume we have the following code: abstract class Base1 { protected int num;
I have the following class: public abstract class AbstractParent { static String method() {
I have the following abstract Django models: class Food(models.Model): name = models.CharField(max_length=100) class Meta:
Lets say i have the following c# classes: abstract class a { protected abstract
I have the following abstract class: public abstract class TemplateBase { public abstract string
If have following class public abstract class MyBaseClass : BaseClass { public override string
I have following class public abstract class Rule { protected Rule() { Nodes =

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.