um, what does the '&' mean? is it a pointer declaration? can somebody explain to me how's this working? thanks! =)
edit: oh, and could you please tell me what's that 'const' keyword doing there? I'm sorry but I'm really having a hard time trying to understand this code, once again, thanks :)
thanks dude, I really didn't bother reading the function tutorial coz I thought I knew that already since we studied functions last semester.. I guess i'll have to read the tutorials from the start so that I wont miss anything, thanks alot, like 1,000 times ^_^
edit:
oh, and one more thing I'd like to ask, in this code:
#include<iostream.h>
class mult
{
int *x, *y;
public:
mult(int, int);
~mult();
int area(){return (*y**x);};
};
mult::mult(int a, int b)
{
x=newint;
y=newint;
*x=a;
*y=b;
}
mult::~mult()
{
delete x;
delete y;
}
void main()
{
mult rein(1,2);
cout<<rein.area()<<endl;
}
in class 'mult', why can't I change the
int area(){return (*y**x);};
into
1 2
int area;
area=*y**x;
is it because its impossible to perform mathematical operations inside a class? I'm sorry, I'm pretty much a beginner in classes and I want to take the opportunity to ask, thanks again! =D
The example you have found is a Copy Constuctor.
It is used to copy one instance of a class (CExample) to another.
'&' indicates a reference parameter, const indicates that the parameter is constant in the method - IE the method cannot modify it.
you would call it as follows;
1 2
CExample myExample = new CExample(2,3); //Declare instance of CExample
CExample myOtherExample = new CExample(myExample); //Declare another instance can copy myExample data to it.