Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Class structure (Newbie)

Reply
Thread Tools

Class structure (Newbie)

 
 
sam
Guest
Posts: n/a
 
      01-22-2007
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.

 
Reply With Quote
 
 
 
 
Scott McPhillips [MVP]
Guest
Posts: n/a
 
      01-22-2007
sam wrote:
> 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.
>


'public' and 'private' refer to class members. s and g are not class
members, they are input parameters from the world outside the class.

--
Scott McPhillips [VC++ MVP]

 
Reply With Quote
 
 
 
 
Noah Roberts
Guest
Posts: n/a
 
      01-22-2007

sam wrote:
> 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? )


The compiler simply refuses to compile anything that accesses those
variables directly.

 
Reply With Quote
 
amit
Guest
Posts: n/a
 
      01-22-2007

sam wrote:
> 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.


You are not 'inserting' but copying value of s and g into o and t
respectively. o and t will continue to remain private.

 
Reply With Quote
 
Jim Langston
Guest
Posts: n/a
 
      01-23-2007

"sam" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between c structure and c++ structure raghunandan_1081@yahoo.com C++ 9 11-11-2011 07:34 AM
Memory allocation in Structure to Structure pra_ramli@rediffmail.com C++ 2 03-09-2006 05:51 AM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
Copy String structure "A" to string structure "B" Leo Nunez C Programming 3 02-09-2005 05:14 AM
Pointers to structure and array of structure. Excluded_Middle C Programming 4 10-26-2004 05:39 AM



Advertisments