Computer::Computer() 
Computer::~Computer()
void Computer::setspeed ( int p )

what is this 3 sentences mean?
what is the purpose we use it?
i have asked my friend but still a bit blur.
pls help.thanks.

Recommended Answers

All 3 Replies

Computer::Computer() - This is a constructor with no parameters of the class "Computer". A constructor has the same name as its class has. // This is how would look like a constructor with a parameter. For example.

Computer::Computer( int )

A constructor is special function called, when the object is being created, and it has no return type.

Computer::~Computer() - This is the destructor of the class "Computer". You can have unlimited number of constructors in a class, but only one destructor. A destructor is a special function called, when the object is not needed anymore. It has no parameters. And always declared as ~class name().

void Computer::setspeed ( int p ) - This is a function of class Computer, it has no return type ( void ), and it takes an int by parameter. If you take away the 'Computer::' part you can see it looks like just as an ordinary function:

void setspeed( int p )

Void is the return type of the function setspeed( int p ). The "Computer::" part is just represents - this is a function of the class "Computer". Hope it helped a little bit.

Highly recommended links:
Classes & Objects - Constructors - Destructors

I normally don't like to post after such a great explanation, but it's sort of important to point out, that the lines are the implementation of the class. You have the class definition which basically is the structure of the class.... but then you have functions (methods) in the class. Those are the locations where you actually write code for the class methods. You should research ::, which is actually the scope operator, and allows you to do a number of cool things.

thanks for your help. i really appreciate it.all the best.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.