-
August 22nd, 2009, 03:52 AM
#1
Statement cannot resolve adress of overloaded function
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <string>
using std::string;
using std::getline;
class GradeBook
{
public:
void displayMessage()
{
cout << "Welcome to the grade book for course: " << getCourseName()
<< endl;
}
void setCourseName( string name )
{
courseName = name;
}
string getCourseName()
{
return courseName;
}
private:
string courseName;
};
int main()
{
GradeBook myBook;
string myCourseName;
cout << "The initial course name is: " << myBook.getCourseName() << endl;
cout << "Enter new course name: ";
getline( cin, myCourseName );
myBook.setCourseName( myCourseName );
myBook.displayMessage; /* THIS IS WHERE I GET MY ERROR */
return 0;
}
-
August 22nd, 2009, 04:03 AM
#2
Re: Statement cannot resolve adress of overloaded function
Please post your well indented code in [code][/code] bbcode tags.
It looks like you did not actually call the function, i.e., you wrote myBook.displayMessage instead of myBook.displayMessage().
Other things to note: do not use using declarations (e.g., using std::cout) before including a header. In other words, these three lines:
Code:
using std::cout;
using std::cin;
using std::endl;
should be moved to after the #include <string>. The reason is that if you have a using declaration before a header inclusion, the contents of that header could be affected by the using declaration. This applies to using directives as well (e.g., using namespace std).
In fact, as a matter of good habit for the future, consider doing without using declarations and using directives before your class definition, since that is how you would do it when you move your class definition to a header file.
-
August 22nd, 2009, 04:06 AM
#3
Re: Statement cannot resolve adress of overloaded function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|