Function in a class

+1 Uros Trickovic · March 5, 2015
What does this do?
Header file:

    float distancebetween( const Tacka& t );

Cpp file:

float Tacka::rastojanje( const Tacka& t )
    return ( sqrt( ( x-t.x)*(x-t.x) + ( y-t.y)*(y-t.y) ) );

Main Cpp:

    Tacka t1;
    Tacka *pt;
    pt = new Tacka;
    cout << "tacke su na rastojanju " <<
        t1.rastojanje( *pt ) << endl;

I am confused about const Tacka& t
is t object or pointer or adress of something?

Post a Reply


Oldest  Newest  Rating
0 Dol Lod · March 5, 2015
& in C++ means you are passing in the value by reference except you treat it as an object for simplicity. Anyway these two show functions are equivalent in that they do exactly the same thing except & uses slightly different sytnax. The only difference is that  you don't need to dereference b/c & is just shorthand for using pointers. 

void show(int* a)

void show(int& a)
  • 1



Used in many types of software including music players, video games, and many large scale applications.

Bucky Roberts Administrator