//3 things only~ define the name, the members and the object names.
struct structure_name { member1, member2,member3...}object_names;
//Just to give a group of objects, its' particulars; that's the objectives.
How to define a class in C++? What's the difference with structure?
//Same method with structure but a little bit further than structure.
class class_name{ member1,member2..., function1,function2...}object_names;
//Instead of holding only data, class holds functions;that the difference, another important concept is the encapsulation thingy, defining the members into private(accessible by same class or friends)||protected(access by same classes as well as classes derived) ||public classes(access by all members), by default it is set as private mode.
More things to learn~
:: and . are calling methods from the class members.
for example:
#include
using namespace std;
class CRec{
int x, int y;
public:
void set_value (int , int );
int area() {return(x*y);} // inline function
};
//member function defination
void CRec::set_value(int a, int b) {
x=a;
y=b;
}
int main(){
CRec rect;
rect.set_value(3,4); //defining member value
cout<<"area:"<
}
No comments:
Post a Comment