Hello,
I'm following along with the Live Lessons C++ video tutorial. I did the entire chapter/all the exercises correctly yesterday, and now today, I tried to do it from memory, for some additional practice/re-enforcement. I know that the main can access the header file, but for some reason, my constructor, or any other object, cannot access any other methods other than the following when I try to access it
(i.e. when I click the "." after the object): 'courseName,' 'GradeBook,' and 'setCourseName.'"
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
|
#include <iostream>
#include <string>
using namespace std;
#include "GradeBook.h"
int main()
{
string nameOfCourse;
GradeBook GradeBookX("02 Data Structures and Algorithms in C++");
GradeBook.getCourseName();
return 0;
}
|
#ifndef GRADEBOOK_H
#define GRADEBOOK_H
#include <iostream>
#include <string>
using namespace std;
class GradeBook{
private:
string courseName;
public:
GradeBook(string name){
setCourseName(name);
}
void setCourseName(string name){
if (name.length() <= 25)
courseName = name;
if (name.length() > 25)
{
courseName = name.substr(0,25);
cout << "\nYour course name " << name << "exceeds the maximum alloted characters(25). File has been shortened to first 25 characters." << endl;
}
string getCourseName(){
return courseName;
}
void displayMessage(){
cout << "\nWelcome to the GradeBook for " << getCourseName() << "!" << endl;
}
};
#endif // GRADEBOOK_H
|
C:\Users\Leo\Documents\Test_Project\main.cpp|26|error: expected ';' after class definition|
C:\Users\Leo\Documents\Test_Project\GradeBook.h||In member function 'void GradeBook::setCourseName(std::string)':|
C:\Users\Leo\Documents\Test_Project\GradeBook.h|32|error: a function-definition is not allowed here before '{' token|
C:\Users\Leo\Documents\Test_Project\GradeBook.h|36|error: a function-definition is not allowed here before '{' token|
C:\Users\Leo\Documents\Test_Project\GradeBook.h|41|error: a function-definition is not allowed here before '{' token|
C:\Users\Leo\Documents\Test_Project\GradeBook.h|64|error: expected '}' at end of input|
C:\Users\Leo\Documents\Test_Project\main.cpp||In member function 'int GradeBook::main()':|
C:\Users\Leo\Documents\Test_Project\main.cpp|16|error: 'class GradeBook' has no member named 'getCourseName'|
||=== Build finished: 6 errors, 0 warnings (0 minutes, 0 seconds) ===|