post  problem using string in class member function

iamthefear (20)   Link to this post
Hi guys, my code is giving me the following error : " 'std::string' : illegal use of this type as an expression"

Could someone tell me what is wrong ive commented the line which is causing the problem. Thanks :) .

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
55
56
57
58
59
60
61
62
63
64
65
66
// student records class example 

#include <iostream>
#include <string>
using namespace std; 

class students

{
private : 

	double mark;
	string student;

public:


	void info(string student, double mark);


		
	
void returninfo();



};



void students::info(string student , double mark)

{

	cout << "  Please input the name of the student " << endl;
    cin >>  student;
	
	cout<< " Please input the students grade " << endl;
	cin >> mark;

	
}

void students::returninfo()
{
	cout << " The students name is " << student << endl;
	cout << " The students grade is " << mark << endl;
}

	int main()

	{

students* stu = new students;

stu->info(string student, double mark) // line causing issue !!!!!!!!!!!!
stu->returninfo();


delete (stu);

system("pause");

		return 0;
	}
Duoas (3485)   Link to this post
You need to read up on variables, functions, and argument passing. It appears that your info() method wants to use arguments passed by reference.
http://www.cplusplus.com/doc/tutorial/functions/
http://www.cplusplus.com/doc/tutorial/functions2/

Good luck!
mcleano (733)   Link to this post
The errors in this are not that hard to fix, but there are a number of them! As Duoas said, read up some more then try again!
hxslacker (7)   Link to this post
Ah,seems that you still don't know how to call a function...Read more about the rules and you can find the problem easily.

This topic is archived - New replies not allowed.