LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   compilling C++ source code (class) error (https://www.linuxquestions.org/questions/programming-9/compilling-c-source-code-class-error-864688/)

hakeemtunde 02-24-2011 12:14 AM

compilling C++ source code (class) error
 
please i try to compile the below code on ubuntu with g++ but i was getting an error message
(fig03_05.cpp:10: error: new types may not be defined in a return type
fig03_05.cpp:10: note: (perhaps a semicolon is missing after the definition of ‘GradeBook’)
fig03_05.cpp:32: error: two or more data types in declaration of ‘main’
).

#include <iostream>
using std::cout;
using std:: cin;
using std::endl;

#include <string>
using std::string;
using std::getline;

class GradeBook
{
public:
void setCourseName ( string name )
{
courseName = name;
}

string getCourseName()
{
return courseName;
}

void displayMessage()
{
cout << "Welcome to the grae book for \n" << getCourseName() << endl;
}

private:
string courseName;
}

int main()
{
string nameOfCourse;
GradeBook myGradeBook;

cout << "Initial course name is :" << myGradeBook.getCourseName() << endl;

cout << "\nPlsease enter the course name" << endl;
getline ( cin, nameOfCourse );

myGradeBook.setCourseName( nameOfCourse );

cout << endl;

myGradeBook.displayMessage();

return 0;
}

any guide will be of help.

thanks

Aquarius_Girl 02-24-2011 12:33 AM

Quote:

Originally Posted by hakeemtunde (Post 4269300)
fig03_05.cpp:10: note: (perhaps a semicolon is missing after the definition of ‘GradeBook’)

Read and understand your above error message and put your code in
Code tags: http://www.linuxquestions.org/questi...do=bbcode#code

hakeemtunde 02-24-2011 12:43 AM

thanks.

Aquarius_Girl 02-24-2011 12:45 AM

You are welcome, use the code tags ALWAYS and mark your thread SOLVED, if you feel...top right of this page.

hakeemtunde 02-24-2011 12:47 AM

Code:

#include <iostream>
using std::cout;
using std:: cin;
using std::endl;

#include <string>
using std::string;
using std::getline;

class GradeBook
{
public:
void setCourseName ( string name )
{
courseName = name;
}

string getCourseName()
{
return courseName;
}

void displayMessage()
{
cout << "Welcome to the grae book for \n" << getCourseName() << endl;
}

private:
string courseName;
};

int main()
{
string nameOfCourse;
GradeBook myGradeBook;

cout << "Initial course name is :" << myGradeBook.getCourseName() << endl;

cout << "\nPlsease enter the course name" << endl;
getline ( cin, nameOfCourse );

myGradeBook.setCourseName( nameOfCourse );

cout << endl;

myGradeBook.displayMessage();

return 0;
}


Aquarius_Girl 02-24-2011 12:50 AM

:D I meant you could have EDITED your first post rather than making a new one for code tags.
Anyway, Welcome to LQ.

colucix 02-24-2011 03:30 AM

Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.

johnsfine 02-24-2011 07:17 AM

Quote:

Originally Posted by Anisha Kaul (Post 4269325)
:D I meant you could have EDITED your first post rather than making a new one for code tags.

Notice that the version in CODE tags in post #5 doesn't just add those tags to the version in post #1. It also adds the missing ; that was responsible for the original error (as you pointed out in post #2).

It would not be appropriate to add the ; by editing post #1.

Since it was a big chunk of code and a tiny change, it would have been nice in post #5 to mention the fact that the correction was adding a ; rather than assume that anyone reading the thread would connect what you said in post #2 to the code in post #5.


All times are GMT -5. The time now is 03:38 PM.