beginner's problem with the use of class

Hello I am new to c++ programing. can anybody help me identify the problem with my code below? it says "need primary expression before abc" for line 17, but even if I added "string", it didn't work

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
#include <iostream>
#include <string>
using namespace std;


class abc
{
public:
    string setabc(string abc)
    {
        privatething= abc;
        return privatething;
    }

    void display()
    {
        cout << "welcome to " << setabc(string abc)<< endl;
    }

private:
    string privatething;
};
int main()
{
    string kk;
    abc object;
    object.display();
    cout << "enter anything";
    cin >> kk;
    object.setabc(kk);
    object.display();
}
in line 17, replace setabc(string abc) with privatething
Also, what is the point of returning abc in setabc function. i would implement it as a void function void setabc(string setabc)
closed account (j3Rz8vqX)
Yeah ats15 is right, the substitution of setabc(string abc) with privatething would be best (logically).
 
   cout << "welcome to " << privatething << endl;


And as he says, why does method setabc need a return value?

If you want a get-accessor make a getabc method.
It would make more sense and would be implemented somewhat like:
1
2
3
4
5
6
7
8
9
string getabc()
{
   return privatething;
}

void setabc(string abc)
{
   privatething=abc;
}
Last edited on
Topic archived. No new replies allowed.