Help doing a class function

Hello all,
I am trying to write a function that enters in a new name for the student name Po, and passing a value instead for that name. I have tried running the code and I keep on getting the error "'setName' cannot be used as a function
setName(name)" I was wondering what I am doing wrong with my code. Here is what I have so far.

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once
#include <iostream>
#include <string>

using namespace std;

class Student
{
private:
	string name;

public:
	Student(string name);
	string getName();
	void setName(string newName);


	~Student();
};

Student::Student(string studentName)
{
	name = studentName;
}

string Student::getName()
{
	return name;
}

void Student::setName(string newName)
{
	name = newName;
}

Student::~Student()
{
}

int main()
{
	string name;
	cin >> name;

	Student* s = new Student("Po");
	
	//
  double setName = 0; 
  setName(name); 
	//

	cout << s->getName();
	return 0;
}
Last edited on
I believe the function should be called : s -> setName(name);

s is the name of the student object declared on line 43 Student* s = new Student("Po") so the program needs to know this is the student who's name you want to change and its a pointer so you need to use -> instead of .

let me know if it doesnt work! and ill see if theres anything else i can find.
Topic archived. No new replies allowed.