"sam" <> wrote in message
news: ps.com...
> Hi,
> See this example of class:-
> class a{
> private:
> int o,t;
> public:
> a( ) { };
> a(int s,int g)
> {o=s;
> t=g;
> }
> };
> My question is see o=s; and t=g;
> What we are doing this we are inserting the public value to private
> value or converting public to private.I new to c++ programming but I
> want to understand the logic behind this or the technique behind
> this(Simply I curious about how this work? )
> Thanks for advance.
a(int s, intg) is a constructor for your class a. It takes two interger
paramters passed by value, then assigns these values to the class's private
variables o and t. The class itself can use it's own private variables in
it's own methods (including constructor).
Incidently, the same thing can be achieved by:
a( const int s, const int g): o(s), t(g) {};
which basically does the same thing except it initializes o and t to the
values instead of assigns them.
|