Error: expected unqualified-id before ')' token

I am using Code::Blocks on Xubuntu. This code intends to set up a student class with a name, id, address and phone number.

K, so I'm getting the error "Error: expected unqualified-id before ')' token" on line 10 of Student.h

But, I don't know what that means. Ideas?

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
#pragma once

#ifndef STUDENT_H
#define STUDENT_H

#include <string>

class Student()
{
    public:
        Student(int ID);
        virtual ~Student();
        void set_name(string Name);
        string get_name();
        void set_address(string Address);
        string get_address();
        void set_phone(string Phone);
        string get_phone();
        void set_id(int ID);
        int get_id();
    private:
        int id;
        string address;
        string phone;
        string name;
};

#endif // STUDENT_H 


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
#include "Student.h"

Student::Student(int ID)
{
    id=ID;
    //ctor
}

Student::~Student()
{
    //dtor
}

Student::set_name(string Name)
{
    name = Name;
}

Student::set_address(string Address)
{
    address = Address;
}

Student::set_phone(string Phone)
{
    phone=Phone;
}

Student::set_id(int ID)
{
    id=ID;
}

Student::get_id()
{
    return id;
}

Student::get_address()
{
    return address;
}

Student::get_phone()
{
    return phone;
}

Student::get_name()
{
    return name;
}


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
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "include/Student.h"



using namespace std;

int main(int argc,char** argv[])
{
    vector<Student> Students;
    int temp_id;
    string temp_str;
    ifstream temp;
    temp.open(argv[0]);
    while(cin.getline(temp_id))
    {
        Student empty = new Student(temp_id);
        empty.set_name(getline(temp));
        empty.set_address(getline(temp));
        empty.set_phone(getline(temp));

        Students.push_back(empty);
    }
    return 0;
}
Last edited on
I think that the compiler reports a number of the statemeent where it found an error, does not it? Why do we have to seek the error?
Sorry, it reports it on line ten of Student.h

class Student()
Lines 27-29 use temp even though it's commented out.

You also didn't include <string> in student.h
The first thing I see wrong is your class declaration.
 
class Student()

A class declaration doesn't take parenthesis.
It should be simply
 
class Student


edit:
Other errors:
1) Your setters in Student have a void return type in the declaration, but not in the definition. The declaration and definition must agree.
2) As Branflakes mentioned, you didn't include <string>
3)
 
Student empty = new Student(temp_id);

This isn't going to work. new returns a pointer.
Last edited on
K I fixed those things, but I'm still getting that same error. I updated the code above.
Thanks abstraction! That got it.
Topic archived. No new replies allowed.