CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2009
    Posts
    2

    Question 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;

    }

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    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.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Aug 2009
    Posts
    2

    Re: Statement cannot resolve adress of overloaded function

    Oh, right.. thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured