This Pointer Help!!

Hey guys. I dont get this coding. Could you please explain? Thanks alot
A class has only one int member, x;

calling testObject(12); assigned x = 12;

then it is showing different ways a class data can be used.

Just by using x; class member can directly use class data without this pointer.
By using this pointer as "this->"
or de-referencing this like this: "*this.". once a pointer is de-referenced, it no longer is used with ->

Last edited on
1. is Test the name of the class?

2. could u explain abit more on the public and private part?

3. Test::Test (int value )
: x(value)

Whats that about?

4. void Test::priny() cont

and that too?

Sorry i suck at this :-/
I would quickly tell because proper answers cannot be told here and I suggest taking a beginner C++ book and read it till end or atleast till virtual functions.

Test is the name of the class.

private means that only class members can private members.

protected means that class members as well well as inherited classes can access them.

public means that data/members are accessible through the class object too apart from class members and inherited class members.

its a constructor doing the initialization for the class object.

test::print is a const function which means, you cannot change class instance/state inside this function. you can just do read only stuff here.

Last edited on
Sorry i suck at this :-/

In order to not suck, you need to learn more. Asking questions here is good to a point. However, when you lack general understanding of some of the basic concepts of C++ syntax, it may be more useful to spend some time taking a class or reading some tutorials. There is a great tutorial on this site. A couple chapters dealing with classes are at the following links. These chapters will begin to answer most of your questions.
Topic archived. No new replies allowed.