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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:12:25+00:00 2026-06-17T05:12:25+00:00

Suppose I am defining a surface object class surface { private: vector<point> points_; vector<hexFace>

  • 0

Suppose I am defining a surface object

class surface
{
private:
    vector<point> points_;
    vector<hexFace> hexFaces_;
}

I have already written a point class, which is very necessary, but as for hexFace, actually it is very simple, it is just a list of four point labels, that is int[4]. And I don’t need to do any complex operation on it.

So my question is: what is the most efficient way in defining such an hexFace object. Should I use struct, or I’d better go with a class or anything else? What would you do? Thanks

And if I need to go with class, can I defining another class in the current class in a nesting way? If I can, do I have to write its constructors within this file also?

Does a struct need a constructor to initialize it?

  • 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-17T05:12:26+00:00Added an answer on June 17, 2026 at 5:12 am

    You ask several questions:

    what is the most efficient way in defining such an hexFace object.

    Run-time efficiency will be about the same for any solution you choose. Lines-of-code efficiency, or maintainer-programmer-brain-power efficiency is probably more valuable.

    If you are limited to pre-C++11 features, I’d use:

    struct hexFace {
      int labels_[4];
    };
    

    If you can use C++11 features, try:

    class surface
    {
    private:
        std::vector<point> points_;
        std::vector<std::array<int, 4>> hexFaces_;
    }
    

    Should I use struct, or I’d better go with a class or anything else?

    struct and class are nearly synonymous. Use whichever you think expresses your intent more clearly. As for “something else”, try std::array

    can I defining another class in the current class in a nesting way?

    Yes, you can. Try:

    class surface
    {
    private:
        class hexFace { public: int lables[4]; };
        vector<point> points_;
        vector<hexFace> hexFaces_;
    };
    

    If I can, do I have to write its constructors within this file also?

    You may, or you may choose to write it elsewhere, or you may choose to omit the user-defined constructor altogether.

    Here is how to write it inline:

    class surface {
    public:
        class hexFace { public: hexFace() { std::cout << "inline constructor!\n" } };
    }
    

    Here is how to write it externally

    class surface {
      public:
      class hexFace {
        public:
          hexFace();
      };
    
    // in another file ...
    surface::hexFace::hexFace() { std::cout << "extern constructor\n"; }
    

    Does a struct need a constructor to initialize it?

    Neither a class nor a struct require a user-defined constructor, but both allow them.

    struct X {
      X() { std::cout << "in struct constructor!\n"; }
    };
    class Y {
      public: 
        Y() { std::cout << "in class constructor!\n"; }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a static method of my class that returns an object of
I have an advanced C++ question: Suppose I have a mmap_allocator template class, which
Let's suppose we have a base class which has a virtual method: class BaseClass
Suppose we have the name written in any none-latin letters - languages, like Arabic,
Suppose I have a class Baz that inherits from classes Foo and Bar ,
Suppose I have a simple model, such as Record: @Model public class Record {
Suppose we have following two classes: class Temp{ public: char a; char b; };
Suppose we have a (toy) C++ class such as the following: class Foo {
Suppose I have multiple roles, each one defining a set of items: package A;
I have seen the following style of defining class members; however, I have only

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.