Re: New to class why am I having sooo much trouble accessing privates
From: Karl Heinz Buchegger (kbuchegg_at_gascad.at)
Date: 11/14/03
- Next message: forums_mp: "Re: [C++] Constructor Help"
- Previous message: Ulrich Eckhardt: "Re: [C++] Constructor Help"
- In reply to: sparks: "Re: New to class why am I having sooo much trouble accessing privates"
- Next in thread: sparks: "Re: New to class why am I having sooo much trouble accessing privates"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 14 Nov 2003 10:28:07 +0100
sparks wrote:
>
> Ok so I am not totally blown away here.
>
> in my header file
> declare the function in public as
>
> void test::FormatARY()
> this will allow the function to access the private variables?
>
This is a *member* function
It is part of the class test and since it is a member of
that class it has access to all the internals of that class.
> in the cpp file
>
> void FormatARY() or void test::FormatARY() << which is correct?
the second one.
void FormatARY() freestanding function which doesn't have
any connection to class test. It is just
a function.
void test::FormatARAY() Member function of class test. It is part
of that class and thus can use everything
inside that class.
> and in main to initialize the array
> its just
> FormatARY() ?
No. You need an *object* of type class test!
Member functions work on objects, they are part of that
object.
int main()
{
test MyObj; // <- this is the object
MyObj.FormatARY(); // and now tell the MyObj object
// to invoke its member function FormatARY
}
A class is just a blueprint. It tells the compiler: whenever you have
an object of that type, this is what it looks like. A class declaration
by itself is a dead thing without much use, just like a blueprint of a
house is a dead thing. Only when you instantiate an object of such
a class type, that object comes to live and can do things. It is the
object that is the active part in your program, not the class. You
give request to that object ( MyObj.FormatARAY() <- Dear MyObj
object, I want you to execute your FormatARY() member function )
-- Karl Heinz Buchegger kbuchegg@gascad.at
- Next message: forums_mp: "Re: [C++] Constructor Help"
- Previous message: Ulrich Eckhardt: "Re: [C++] Constructor Help"
- In reply to: sparks: "Re: New to class why am I having sooo much trouble accessing privates"
- Next in thread: sparks: "Re: New to class why am I having sooo much trouble accessing privates"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|