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 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 figure out why I can't understand how to do this
Alright so I'm trying to get this class work: public boolean hasPoint(Point p){ for
Alright, I'm just trying to learn about using Contact information, but I'm a bit
Alright, I am trying to accomplish this: When a user clicks a button that
Alright, I'm trying to recreate the old classic, Missile Command, using OpenGL in C++.
Currently I'm trying to understand dependency injection better and I'm using asp.net MVC to
Alright, I'm trying to understand follow sets and I think I got it except
Alright I've been trying to find an answer to this for hours already but
Alright I have been trying to figure this out and I read the MSDN
Alright so what I am trying to do is essentially create a program that,

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.