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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:13:33+00:00 2026-05-23T00:13:33+00:00

Consider the following code: class Rectangle { public: // Constructors Rectangle(){ init(0,0); } Rectangle(int

  • 0

Consider the following code:

class Rectangle
{
public:
    // Constructors
    Rectangle(){ init(0,0); }
    Rectangle(int h, int w){ init(h,w); }

    // Methods
    void init(int h, int w)
    {
        _h = h;
        _w = w;
    }

    // Getters / Setters
    double get_h(void){ return _h; }
    double get_w(void){ return _w; }
    void set_h(double h){ _h = h;  }
    void set_w(double w){ _w = w;  }
    std::string get_name(void){ return _name; }
    void set_name(std::string name){ _name = name; }

private:
    // Private Members
    int _h, _w;
    std::string _name;
};

class House
{
public: 
    // <BEGIN PASSTHROUGHS>
    std::string get_b_name(void){ return _base.get_name() };
    std::string get_r_name(void){ return _roof.get_name() };
    void set_b_name(std::string name){ _base.set_name(name); }
    void set_r_name(std::string name){ _roof.set_name(name); }
    // </END PASSTHROUGHS>

private:
    // Private Members
    Rectangle _base;
    Triangle  _roof;
};

This code works fine.

My question deals with the “passthrough” functions in the House class, enclosed by the PASSTHROUGHS tags. Is this the best way to do this? The arguments and return types will always match and there is no “intelligence” in these passthrough functions other than to make things cleaner and more straightforward.

My instinct would be something like one of the following:

get_b_name = _base.get_name;

// OR

std::string get_b_name(void) = _base.get_name;

… but neither seem to work unfortunately and it was only wishful thinking in the first place. If there are no easier options, telling me that is fine too. Thanks!

  • 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-23T00:13:34+00:00Added an answer on May 23, 2026 at 12:13 am

    The problem, I think, is conceptual. Your design is quite un-object oriented in that the house does not represent an entity, but rather provides a bit of glue around the components. From that standpoint, it would make more sense to provide accessors to the elements, rather than pass-through functions:

    class House {
       Rectangle _base;
       Triangle  _roof;
    public:
       const Rectangle& base() const {
          return _base;
       }
       const Triangle& roof() const {
          return _roof;
       }
    };
    

    I imagine that this is just a toy example, but the same reasoning applies: a class should represent an entity on which a set of operations are preformed, in some cases those operations might be implemented in terms of internal subobjects, but they are still operations on the type, and how they are gathered is an implementation detail.

    Consider:

    class House {
       Thermostat t;
    public:
       int temperature() const {
          return t.temperature();
       }
    };
    

    From the user point of view the house has a temperature that can be read, and in this particular implementation, it is read from a thermostat that is a member. But that is an implementation detail. You might want to later install more thermostats in the house and substitute the single reading by an average of the readings, but that will not change the fact that the entity House (in this model) has a temperature.

    That is, you should not be thinking in implementing pass-through functions, but rather on implementing features of the type. If the implementation happens to be a single forwarding to an internal method, that is fine.

    But if the type contains internal members and it makes sense to access properties of the members, consider that it might be that you actual type should just provide access to its internal members. Consider that you want to move a piano inside the house, then you might just provide access to the door member and let the user check:

    class House {
       Door d;
    public:
       Door const & door() const {
          return d;
       }
    };
    bool can_enter_piano( House const & h, Piano const & p ) {
       return h.door().width() > p.size();
    }
    

    There is no need to provide House::get_door_width(), and House::get_door_color() so that you can describe the entrance to a friend, and House::get_door_handle() so that they can know when they arrive…

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

Sidebar

Related Questions

Consider the following code: public class Vehicle { public void StartEngine() { // Code
Consider the following code: public class Bar { Foo foo; void Go() { foo
Consider the following code: abstract class SomeClassX<T> { // blah } class SomeClassY: SomeClassX<int>
Consider the following code: class Program { static void Main(string[] args) { A a
Consider the following code: class Program { static void Main(string[] args) { new Program().Run(args);
Consider the following code : public class RandomClass { private readonly string randomString; public
I have the following code class sample { public void update(List l) { l
Consider the following code parts: this is Timing.h: class Timing { public: //creates a
Consider the following code : class TextMessage{ public : TextMessage(){}; TextMessage(std::string _text):text(_text){} std::string text;
Consider the following code snippet below. class X { public String toString() { return

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.