Need help with pointers - I think

Hi. I am trying to run the below code but I am having an issue compiling. Visual Studio is telling me that I need to create pointers but everytime I try, I run into more issues. Could some please take a look at my code and tell me whats wrong with it?

The VS Errors are below too


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
67
68
69
70
71
72
73
74
75
76
#include "stdafx.h"
#include <iostream>
#include <iomanip>  
#include <string>
#include <sstream>

using namespace std;

class Student
{
private:
long int SSN;
string name;

public:
	Student();
Student(string name, long SSN);
long setSSN(long);	
string setName(string);
string getName(string name);
long getSSN(long SSN);

};

Student::Student()
{
	name= "unassigned";
	SSN = 123456789;
}

Student::Student(string name, long SSN)
{
}


long Student::setSSN(long sSSN)
{
sSSN = SSN;
return sSSN;
}

string Student::setName(string sName)
{
sName = name;
return sName;
}

long Student::getSSN(long SSN)
{
if (SSN > 0)	
return SSN;
}


string Student::getName(string name)
{

return name;

}

int main()
{

Student student1, student2("John Doe", 123456789);


cout << "Name for student1 is " << student1.getName << "and ssn is " << student1.getSSN;


cout << "Name of student2 is " << student2.getName << "and ssn is " << student2.getSSN;

system("PAUSE");

return 0;
}


All errors occur in my main method.

Error 1 error C3867: 'Student::getName': function call missing argument list; use '&Student::getName' to create a pointer to member
Error 2 error C3867: 'Student::getName': function call missing argument list; use '&Student::getName' to create a pointer to member
Error 3 error C3867: 'Student::getName': function call missing argument list; use '&Student::getName' to create a pointer to member
Error 4 error C3867: 'Student::getSSN': function call missing argument list; use '&Student::getSSN' to create a pointer to member
Error 5 error C3867: 'Student::getSSN': function call missing argument list; use '&Student::getSSN' to create a pointer to member
Error 6 error C3867: 'Student::getName': function call missing argument list; use '&Student::getName' to create a pointer to member
Error 7 error C3867: 'Student::getName': function call missing argument list; use '&Student::getName' to create a pointer to member
Error 8 error C3867: 'Student::getName': function call missing argument list; use '&Student::getName' to create a pointer to member
Error 9 error C3867: 'Student::getSSN': function call missing argument list; use '&Student::getSSN' to create a pointer to member
Error 10 error C3867: 'Student::getSSN': function call missing argument list; use '&Student::getSSN' to create a pointer to member


First of all why are you returning on your set functions? Secondly I wouldn't use setters/getters I would instead use initializers and operator<<
Also you are not actually using the ssn for adding or anything so you can use a string.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Student
{
private:
    const std::string ssn , name; //guessing you are not modifying?

public:
    Student( void ); //default
    Student( std::string& , std::string& ); //ssn and name passing by reference to save time instead of creating a copy
    friend std::ostream& operator<< ( std::ostream& , const Student& ); //friend has access to private
};

Student( void ) : ssn( "Unasigned" ) , name( "Unasigned" ) {}
Student( std::string &ssn , std::string &name ) : ssn( ssn ) , name( name ) {}

std::ostream& operator<< ( std::ostream &stm , const Student &stu )
{
    return( stm << "Name: " << stu.name << "\nSocial: " << stu.ssn );
}


Edit oh and your getter functions are pointless why are you setting a value equal to the thing you want to return then returning the other value? You can just return the thing you want to.

1
2
3
4
std::string get_name( void )
{
    return( name );
}


And the reason you get an error is because for one you have a string as a parameter that you shouldn't use or even need and two you need to call the function and by calling functions you put () at the end. ( line 68 / 71 )http://www.cplusplus.com/doc/tutorial/functions/
http://www.cplusplus.com/doc/tutorial/functions2/
Last edited on
I should have put the requirements in the first post. Sorry about that.

Create a class named Student. The class should consist of the following private member variables: social security number and name (last, first or first, last?). The social security number (SSN) should be a long integer. The name variable must be a character array of 80 characters.
Create the following class member functions: setSSN, getSSN, setName, getName. Each of these member functions should be public.
The setSSN function should accept 1 argument and update the the social security number member variable. Do not allow the the social security number to be set to zero or less than zero. The getSSN should return the class SSN.

The setName member function should accept one string argument. Use the argument to update the name class member variable. Do not update the class variable for name if the argument has a length of 0. (This indicates the name in the argument is "empty".) The getName method should return the class value for name.
Create a default constructor for the Student class. This constructor will accept no arguments. Use the default constructor to initialize the social security number to 999999999 and the name to "unassigned".
Make sure all your methods are defined in the implementation section of the class. Do not use any inline class member functions.
Create a main function. In the main function create two Student objects. Use the appropriate get functions to print all the values of all the member variables for the first Student object. For the second object, use the set methods to change the student name to John Doe and the social security number to 123456789. Use the appropriate get functions to print all the values of all the member variables for the second Student object.
Do not print from the Student class. Instead you will retrieve the data in the main() function and print from main.
back to what I said you need to use () when you are calling a function. That will fix your problem just change lines 68 and 71. As far as the assignment I think your teacher isn't thinking very clearly. First of all you are not actually using the ssn as a number and secondly what happens if the social starts with 0 or 00? ex: 002-41-1234. for a long that would be equivalent to 2411234 not 002411234 if it was a string though it would. Also social security numbers can not start with an 8 or 9 since those are reserved for advertisements or something and there are a few other cases that it can not start with like 000 or 666.

Also your assignment says
use the default constructor to initialize the social security number to 999999999 and the name to "unassigned."

You are not initializing you are just assigning a value to those. To initialize you need to do something like this
 
Student::Student() : ssn( 9999999999 ) , name( "unassigned" ) {}


Also I don't see the assignment saying to overload the Student object it just says create two student objects and with the second object use the set functions.

Also it says to use a character array for the name and you are using a string.
Topic archived. No new replies allowed.