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

  • Home
  • SEARCH
  • 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 6957819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:03:34+00:00 2026-05-27T15:03:34+00:00

I know I’ve just asked a question about this, but I cannot figure out

  • 0

I know I’ve just asked a question about this, but I cannot figure out what I’m doing wrong. I’ve rewritten just the small part and cannot find any errors (used C++ function in parent return child as reference)

My code:

#include <iostream>
#include <stdlib.h>
#include <cstring>

using namespace std;

template<class Derived>
class Entity {
    private:
        string _name;
    public:
        const string& name() const;
        Derived& name( const string& );
        Derived* This() { return static_cast<Derived*>(this); }
};

class Client : Entity<Client> {
    private:
        long int _range;
    public:
        const long int& range() const;
        Client& range( const long int& );
};

const string& Entity::name() const {
    return _name;
}

Derived& Entity::name(const string& name) {
    _name = name;
    return *This();
}

const long int& Client::range() const {
    return _range;
}

Client& Client::range( const long int& range ) {
    _range = range;
    return *this;
}

int main() {
    Client ().name("Buck").range(50);
    return 0;
}

The result:

untitled:25: error: ‘template<class Derived> class Entity’ used without template parameters
untitled:25: error: non-member function ‘const std::string& name()’ cannot have cv-qualifier
untitled: In function ‘const std::string& name()’:
untitled:26: error: ‘_name’ was not declared in this scope
untitled: At global scope:
untitled:29: error: expected constructor, destructor, or type conversion before ‘&’ token
untitled: In function ‘int main()’:
untitled:13: error: ‘Derived& Entity<Derived>::name(const std::string&) [with Derived = Client]’ is inaccessible
untitled:44: error: within this context
untitled:44: error: ‘Entity<Client>’ is not an accessible base of ‘Client’

I’d be very grateful for answers (my incompetence might be due to sleep deprivation though :D)

  • 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-27T15:03:35+00:00Added an answer on May 27, 2026 at 3:03 pm

    You need to implement your specialized functions as this:

    template<>
    const string& Entity<Client>::name() const {
        return _name;
    }
    
    template<>
    Client& Entity<Client>::name(const string& name) {
        _name = name;
        return *This();
    }
    

    and also add public inheritance:

    class Client : public Entity<Client>
    

    so you can access name().

    If you want generic implementations:

    template<class x>
    const string& Entity<x>::name() const {
        return _name;
    }
    
    template<class x>
    x& Entity<x>::name(const string& name) {
        _name = name;
        return *This();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know we already have many posts about this topic, but I just cannot
Know this might be rather basic, but I been trying to figure out how
I know that this is a very commonly asked question, but all of the
I know this question was asked before, but the answer didn't work for me.
I know this is a very subjective question but as text rendering in WPF
I know this is a pretty basic question, but I don't know how to
I know this question has been around, but I found answers a bit foggy,
I know this has been asked a million times, but I haven't had much
know nothing about php, but I have this script that reads a folder and
I know this has probably been answered as it seems a common question but

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.