I am new to C++ OOP concepts. The problem I am having currently with the string declaration in getter and setter function. I use eclipse IDE and the error I get is
error: cannot convert 'Student::getname' from type 'std::__cxx11::string (Student::)() {aka std::__cxx11::basic_string<char> (Student::)()}' to type 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}'
return getname;
The code is as follows:
#include<iostream> #include<string.h> using namespace std; class Student { private: int rollno; string name; string school; public: void setrollno(int i) { rollno =i; } void setname(string n) { name =n; } void setschool(string s) { school =s; } int getrollno() { return rollno; } string getname() { return getname; } string getschool() { return school; } }; int main() { Student A; A.setrollno(3); cout << A.getrollno(); A.setname("vinod"); cout << A.getname(); A.setschool("carmel"); cout << A.getschool(); } Could anyone tell me what the problem is?
return getname;Is that what you intended?return name;is that what you intended? Your comment's code is exactly the same as in the question ;)#include<string.h>with#include<string>.string.honly declares the c-functions for character array manipulation.