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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:02:34+00:00 2026-05-15T06:02:34+00:00

Alright, im trying to understand this, so a class is simply creating a template

  • 0

Alright, im trying to understand this,

so a class is simply creating a template for an object.

class Bow
{

int arrows;

};

and an object is simply creating a specific item using the class template.

Bow::Bow(arrows)
{
arrows = 20;
}

also another question, public specifiers are used to make data members avaible in objects and private specifiers are used to make data memebers only avaialble inside the class?

  • 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-15T06:02:35+00:00Added an answer on May 15, 2026 at 6:02 am

    The description you gave is mostly correct but your examples don’t show what you are describing.

    A class describes a set of data members and member functions which can be called on those data members:

    class Bow
    {
    public:
       //Constructor
       Bow::Bow()
       {
         arrows = 20;
       }
    
       Bow::Bow(int a)
       {
         arrows = a;
       }
    
    
       //member functions (in this case also called accessors/modifiers)
       void getArrows(int a) const
       {
         return arrows;
       }
    
       void setArrows(int a)
       {
         arrows = a;
       }
    
    protected:
      int arrows;
      };
    

    And an object of a class is simply an instance of that class.

    //b and d are objects of the class Bow.
    Bow b(3);//The constructor is automatically called here passing in 3
    Bow d(4);//The constructor is automatically called here passing in 4
    Bow e;//The constructor with no parameters is called and hence arrows = 20
    

    Note: I purposely avoided the use of the word template that you used because it’s used for something entirely different in C++ than what you meant.


    To understand public/private/protected specifiers:

    public: means that objects of the class can use the members directly.

    protected: means that objects of the class cannot use the members directly. Derived classes that are based on that class can use the members.

    private: means that objects of the class cannot use the members directly. Derived classes that are based on that class cannot use the members either.

    So in the above example:

    Bow b(3);
    b.arrows = 10;//Compiling error arrows is not public so can't be accessed from an object
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, I'm trying to read a comma delimited file and then put that into
Alright, so I'm trying out C++ for the first time, as it looks like
Alright, I'm trying to get arguments to work properly with a small test application.
Alright, after doing a ton of research and trying almost every managed CPP Redist
Alright so here is the deal. I am trying to make a application that's
Alright. So I figure it's about time I get into unit testing, since everyone's
Alright, currently I have my SWF hitting a php file that will go and
Alright, I have been doing the following (variable names have been changed): FileInputStream fis
Alright. So I have a very large amount of binary data (let's say, 10GB)
Alright, I know how the fieldset / legend works out in HTML. Say you

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.