Originally Posted by
HawkLord
I compiled it and it showed the result of add::add_xy() is -35. just to clarify does the code (void) mean to return?
Nothing. It's void of return.
int funct() - returns an int
char function() - returns a char
etc
void function() - returns nothing
Also:
int funct( void ) - returns an int
char function( void ) - returns a char
etc
void function( void ) - returns nothing
The (void)'s just mean that the functions don't take any parameters. It's strictly not necessary to have them there, but I'm somewhat pedantic about layouts etc.
Do you understand why it returned 35 though?
Here's another example -
Code:
class Add
{
private:
int x;
int y;
public:
Add( int New_x, int New_y ) : x( New_x ), y( New_y )
// This is called an itilisation list. Just another way of intialising class members
{
}
int Add_XY ( void )
{
return ( x+y );
}
};
int main( void )
{
int result, User_x, User_y;
std::cout<< "Enter int one: ";
std::cin >> User_x;
std::cout<< "Enter int two: ";
std::cin >> User_y;
Add MyInstance( User_x, User_y );
result = MyInstance.Add_XY();
std::cout<< "The result of Add::Add_XY() is: " << result;
return 0;
}