is this a pointer?

Hi everyone, I was reading the tutorials about classes (I) and I happen to have found this argument
1
2
3
CExample::CExample (const CExample& rv) {
  a=rv.a;  b=rv.b;  c=rv.c;
  }

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 :)
Last edited on
1. The "const" ... as far as i know, it makes u able to pass a constant object for to the argument.

2... read this one^^ http://www.cplusplus.com/doc/tutorial/functions2.html
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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#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=new int;
y=new int;	
*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
Last edited on
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. 
Topic archived. No new replies allowed.