Help with understanding the code

hello
i need to know how this part of the code works... i have very bad teachers in school so i need your help

i need only part of the 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
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <fstream>

using namespace std;

class razlomak{
private:
	float brojnik;
	float nazivnik;
public:
razlomak(float br, float na){
	brojnik=br;
	nazivnik=na;
}
razlomak(){
	brojnik=1; nazivnik=1;
}

razlomak operator *(const razlomak&r){
	return razlomak (r.brojnik*brojnik, r.nazivnik*nazivnik);
}

void ispis(){
cout<<brojnik<<"/"<<nazivnik<<"="<<brojnik/nazivnik<<endl;}

};


int main(){
razlomak a(1,2), b(2,3);
razlomak c=a*b;
c.ispis();
return 0;
}



okay now what i dont understand in here is

1
2
razlomak operator *(const razlomak&r){
	return razlomak (r.brojnik*brojnik, r.nazivnik*nazivnik);


what i need is what is this "operator *" doin
why do i need "const"... and ""razlomak&r"
and how can i use "r." when i have "razlomak=ra" on top is it because of "razlomak&r"?
closed account (zb0S216C)
operator *
This indicates which operator is being overloaded.

const razlomak&r
This is a constant reference to a razlomak instantiation. The associated const qualifier indicates that the referenced object cannot be altered.

return razlomak (r.brojnik*brojnik, r.nazivnik*nazivnik);
This statement is creating a new instantiation of razlomak. During the declaration, two arguments are passed to the constructor of the object. These arguments are as follows:

Argument 1: The product of the r.brojnik*brojnik computation.
Argument 2: The product of the r.nazivnik*nazivnik computation.

Goran Gagro wrote:
how can i use "r." when i have "razlomak=ra" on top is it because of "razlomak&r"? (sic)

I don't understand.

Wazzak
Topic archived. No new replies allowed.