0

i have a class

class Studentas
{
 public:
 static const int CPaz=10;
 private:
 string pavarde, vardas, grupe;
 double paz[CPaz],   // paþymiø masyvas
 np;          // paþymiø kiekis
 double vidurkis;
 double STsk;
 public:
 Studentas(): pavarde(""), vardas(""), grupe(""), np(0), STsk(1),vidurkis(0)
 { }
 double imtinp(){return np;}
 double imtipaz(int i){return paz[i];}

 void Deti(string pav, string vard, string grup, int np, int pz[],double vid);
 void grupeDETI(string grp,double vidurk){grupe=grp;vidurkis+=vidurk;}

 double iv(){return vidurkis;} <---------------------------------------THE ONES IM USING
 void isvestiVID(){vidurkis/=STsk;}
 void pridetiSK(){STsk++;}

 string ig(){return grupe;} <---------------------------------------THE ONES IM USING
 string Spausdinti(int i);
 string SpausdintiGrupes();
};

the bool i was using bool

myfunction(Studentas const &d1,Studentas const &d2){return (d1.iv() > d2.iv() || d1.iv()==d2.iv()     && d1.ig() < d2.ig());} 

vector<Studentas> grupe;(with whatever length)

sort(grupe.begin(), grupe.end(),myfunction);

and i get an error, " cannot convert 'this' pointer from 'const Studentas' to 'Studentas &' "

EDIT : i use void functions to get my variables.

EDIT2: thanks for all the help, i think i'll just bubble this one out.Dont have the time to waste, thanks again for the help.

EDIT3: dun goofed on my operator overlays, the method below works.

Cœur
  • 37,241
  • 25
  • 195
  • 267
jonas rudzionis
  • 115
  • 2
  • 8
  • Where exactly is the error occuring? – Codor Oct 09 '14 at 14:51
  • Make `ig` and `iv` `const` so you can use those with `const` objects. You might also want to implement `>`, `<`, and `==` instead of needing to provide access to private members. – crashmstr Oct 09 '14 at 14:52

1 Answers1

3

Mark your methods as const:

double iv() const {return vidurkis;} 

This way you'll be able to call them on const objects, which is what d1 and d2 are.

All methods that logically don't need to modify the object should be marked const.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625