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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:52:30+00:00 2026-06-07T13:52:30+00:00

I am a beginner in C++ and am trying to learn it by looking

  • 0

I am a beginner in C++ and am trying to learn it by looking at examples.
Here is an example definition for a class that I don’t understand the meaning completely:

class MyClass{
public:
  std::string name;
  void *data;

  MyClass(const std::string& t_name, void *t_data) : name(t_name), data(t_data) {}
};

Here is what I understand:
name and *data are variables of the class and, MyClass(…) is the constructor. The meaning of : is the left side class is derived from the right hand side class. However, what is the meaning of this part of the code:

MyClass(const std::string& t_name, void *t_data) : name(t_name), data(t_data) {}

Here are the questions:

  1. what are “t_data” and “t_name”? Are they initial values for “data” and “name”? what is the reason t_ is used here?
  2. what is the meaning of : in the above line?
  3. what is {} at the end of that line?

Thanks for the help.
TJ

  • 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-07T13:52:31+00:00Added an answer on June 7, 2026 at 1:52 pm

    what are “t_data” and “t_name”? Are they initial values for “data” and “name”?

    They are the arguments passed to the constructor. If an object were created as

    MyClass thing("Fred", some_pointer);
    

    then, in the constructor, t_name has the value "Fred" and t_data has the value of some_pointer.

    what is the reason t_ is used here?

    Some people like to tag the arguments to give them different names to the class members, but there’s no need to do that unless you want to.

    what is the meaning of : in the above line?

    That marks the start of the initialiser list, which initialises the class member variables. The following initialisers, name(t_name), data(t_data) initialise those members with the constructor’s arguments.

    what is {} at the end of that line?

    That’s the constructor’s body, like a function body. Any code in their will be run after the members have been initialised. In this case, there’s nothing else to do, so the body is empty.

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

Sidebar

Related Questions

Background: I am a beginner javascript developer who is trying to understand and learn
I was just trying to learn the syntax of the beginner things, and how
Beginner here trying to get a pipeline working in bash. If somebody can see
One friend of mine is beginner programmer and he is trying to learn classic
I am a beginner to the Linux Kernel and I am trying to learn
I am a beginner, trying to learn how to use POCO C++ library (
I am still a beginner but trying to learn so probably doing something extremely
I am a beginner and I am trying to learn how to add, delete,
I'm trying to learn some ant for a Struts 1.x project that I was
I'm a complete beginner trying to learn Java as my first language. When I'm

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.