expected ')' before 'className'

When I compile the following files (using onlinegdb.com right now), I get the error:
In file included from main.cpp:3:0:
dayType.cpp:8:16: error: expected ‘)’ before ‘dayName’
dayType(string dayName)

I don't have any clue why this is happening, mainly because I don't understand why a constructor call would have a random ) in the middle of parameters. dayType(string )dayName) doesn't make sense to me. What's going on with my code?

main.cpp
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
#include <iostream>
#include <string>
#include "dayType.cpp"
using namespace std;

int main() 
{
    int daysAdded = 0;
    dayType myDay("Monday");
    dayType temp("Sunday");
    cout << "\nDay name:  " << myDay.returnDayName() << endl;
    cout << "Next day:  " << myDay.returnNext() << endl;
    cout << "Previous day:  " << myDay.returnPrevious() << endl;
    cout << "How many days are you adding to the current day?  ";
    cin >> daysAdded;
    cout << "Day with " << daysAdded << " days added:  " << myDay.addDay(daysAdded);
    
    cout << "\n\nDay name:  " << temp.returnDayName() << endl;
    cout << "Previous day:  " << temp.returnPrevious() << endl;
    cout << "Next day:  " << temp.returnNext() << endl;
    cout << "How many days are you adding to the current day?  ";
    cin >> daysAdded;
    cout << "Day with " << daysAdded << " days added:  " << temp.addDay(daysAdded);
    
    return 0;
}


dayType.cpp
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <iostream>
#include <string>

#include "dayType.h"

using namespace std;

dayType(string dayName)
{
    if(dayName == "Sunday")
    {
        dayNum = 1;
    }
    else if(dayName == "Monday") 
    {
        dayNum = 2;
    }
    else if(dayName == "Tuesday") 
    {
        dayNum = 3;
    }
    else if(dayName == "Wednesday") 
    {
        dayNum = 4;
    }
    else if(dayName == "Thursday") 
    {
        dayNum = 5;
    }
    else if(dayName == "Friday") 
    {
        dayNum = 6;
    }
    else if(dayName == "Saturday") 
    {
        dayNum = 7;
    }
    else 
    {
        cout << "Day may have invalid value:  Error code 1.  Exiting...";
    }
}
string returnDayName()
{
    switch(dayType::dayNum)
    {
        case 1:  return "Sunday";
        case 2:  return "Monday";
        case 3:  return "Tuesday";
        case 4:  return "Wednesday";
        case 5:  return "Thursday";
        case 6:  return "Friday";
        case 7:  return "Saturday";
        default: return "Day may have invalid value:  Error code 1.  Exiting...";
    }
}
string returnNext()
{
    int temp = dayNum + 1;
    if(temp > 7) {temp -= 7;} //test to see if using a while loop helps here.  
    switch(temp)
    {
            case 1:  return "Sunday";
            case 2:  return "Monday";
            case 3:  return "Tuesday";
            case 4:  return "Wednesday";
            case 5:  return "Thursday";
            case 6:  return "Friday";
            case 7:  return "Saturday";
            default: return "Day may have invalid value:  Error code 1.  Exiting...";
    }
}
string returnPrevious()
{
    int dayNumTemp = dayNum - 1;
    if(dayNumTemp < 1) {dayNumTemp += 7;}
    switch(dayNumTemp)
    {
        case 1:  return "Sunday";
        case 2:  return "Monday";
        case 3:  return "Tuesday";
        case 4:  return "Wednesday";
        case 5:  return "Thursday";
        case 6:  return "Friday";
        case 7:  return "Saturday";
        default: return "Day may have invalid value:  Error code 1.  Exiting...";
    }
}
string addDay(int daysAdded)
{
    int dayNumTemp = dayNum + daysAdded;
    if(dayNumTemp > 7) {dayNumTemp -= 7;}
    switch(dayNumTemp)
    {
        case 1:  return "Sunday";
        case 2:  return "Monday";
        case 3:  return "Tuesday";
        case 4:  return "Wednesday";
        case 5:  return "Thursday";
        case 6:  return "Friday";
        case 7:  return "Saturday";
        default: return "Day may have invalid value:  Error code 1.  Exiting...";
    }
}


dayType.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#ifndef H_dayType 
#define H_dayType
 
#include <string>  

using namespace std;

class dayType
{
    string dayName = "";
    int dayNum = 0;
    dayType(string dayName);
    string returnDayName();
    string returnNext();
    string returnPrevious();
    string addDay(int daysAdded);
};

#endif 
Last edited on
1
2
3
4
// dayType(string dayName)
dayType::dayType(string dayName) 
{
    // ... 

And likewise, for the other member functions too.

Ideally, do not place using namespace std; at global scope in a header file

And in main.cpp, include the header (instead of the cpp file)
Topic archived. No new replies allowed.