C++ Error when declare Get Method const -


problem const in c++...

myvektor[i].getname().getfirstname() generates error: (see code below)

error 1 error c2662: 'name::getfirstname' : cannot convert 'this' pointer 'const name' 'name &' c:\users\betula\documents\visual studio 2012\projects\c++laboration_2\c++laboration_2\person_test.cpp   215 1   c++laboration_2 

and

3   intellisense: object has type qualifiers not compatible member function             object type is: const name  c:\users\betula\documents\visual studio 2012\projects\c++laboration_2\c++laboration_2\person_test.cpp   215 17  c++laboration_2 

vector , method call main in persontest...

vector<person> mypersons;  showperson(myvektor); 

method:

void showperson(vector<person> &myvektor) { cout << endl << " list of people: " << endl << endl;  for( size_t = 0; < myvektor.size(); i++) { cout << " " + myvektor[i].getname().getfirstname() + " " + myvektor[i].getname().getlastname() << endl;      //cout << " " + myvektor[i].getaddress() + " " + myvektor[i].getaddress()+ " " +     myvektor[i].getaddress() << endl;      cout <<" social security number: " + myvektor[i].getpersnr() << endl;      cout <<" shoe size: " + to_string(myvektor[i].getskonr()) << endl << endl;       } } 

all getmethods declare const there class person & name

const name person::getname() { return my_name; }  const string name::getfirstname() { return firstname; } 

if remove const declare in class person & name works...

any suggestions beginner...

/ nimos

replace const name person::getname() name person::getname() const etc. make functions constant opposed return variable.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -