Guide
1
Any reference to the class should take into account the scope of its visibility.Advantageously the class description file to indicate the beginning of the program code.To do this, write to the design of the form #include "File_name.h".Either insert the code in the same description.Before calling the method initialize the object by writing: CClass1 Obj1, here CClass1 - class name, Obj1 - the name of the object.Along with the object class can be used and pointers for an instance.In this case, declare the cursor and select the memory: CClass
1 * Obj2 = new CClass1 ().
2
Call an object method with the following command: Obj1.metod1 (), is used when accessing the operator "." (Point).When working with a pointer to an instance of an operator put «- & gt;»: Obj2- & gt; metod1 ().Consider the scope of the object or pointer.So, when you declare a variable within a function, it will be the compiler is not visible outside.
3
If a class method is described with the access specifier public, it can cause the above processes from anywhere in the program.Often, however, methods for the protection of the data, given the status of hidden.So, if the declaration by a private function can be accessed only within the class.Call it carried out only within the framework of another instance method of the same class.Protected modifier also covers the use of the method for arbitrary code, but provides the opportunity for children klassov.Primer method call in the derived class: class A // parent class {protected: void funcA ();}; class B: public A // inherited (child) class {public: void funcB () {funcA ();} // Call the parent class method};
4
When referring to a class method in another function of the same class to create an instance of it is unnecessary.It is enough to specify the name of the method and transmitted parametry.Primer calling code: class CClass2 {void func1 (int k);void func2 () {func1 (50);}};
5
There is another way to access the method without creating an instance of the class.However, this requires that this method was declared in the class as a staticheskiy.Primer describe the method in a class: class CClass3 {static int func3 ();} In this case, the method call func3 can be done anywhere in the program by the structure: CClass3 ::func3 ().