B
B Williams
I have been working with this code for a better part of the day and I can't
figure out where I am making a mistake. I can only imagine it is when I
declare multiple paramaters on the constructor because the program compiles
with just one parameter. Can someone look at this and tell me where I made
my error?
This is the error I get while trying to compile.
error C2664: 'GradeBook::GradeBook(const GradeBook &)' : cannot convert
parameter 1 from 'const char [38]' to 'const GradeBook &'
Reason: cannot convert from 'const char [38]' to 'const GradeBook'
No constructor could take the source type, or constructor overload
resolution was ambiguous
Thanks
// GradeBook.cpp
// GradeBook member-function definitions. This file contains
// implementations of the member functions prototyped in GradeBook.h.
#include <iostream>
using std::cout;
using std::endl;
#include "GradeBook.h" // include definition of class GradeBook
// constructor initializes courseName and instructorName with string
supplied as argument
GradeBook::GradeBook(string name, string instructor)
{
setCourseName( name ); // call set function to initialize courseName
setInstructorName( instructor );// call set function to initialize
instructorName
} // end GradeBook constructor
// function to set the course name
void GradeBook::setCourseName( string name )
{
courseName = name; // store the course name in the object
} // end function setCourseName
// function to get the course name
string GradeBook::getCourseName()
{
return courseName; // return object's courseName
} // end function getCourseName
// function to set the instructor name
void GradeBook::setInstructorName( string instructor )
{
instructorName = instructor; // store the instructor name in the object
} // end function setInstructorName
// function to get the instructor name
string GradeBook::getInstructorName()
{
return instructorName; // return object's instructorName
} // end function getInstructorName
// display a welcome message to the GradeBook user
void GradeBook::displayMessage()
{
// call getCourseName and getInstructorName to get the courseName and
instructorName
cout << "Welcome to the grade book for\n" << getCourseName()
<< "!" << endl;
cout << "This course is presented by:\n" << getInstructorName()
<< "!" << endl;
} // end function displayMessage
This is the header file
// GradeBook.h
// GradeBook class definition. This file presents GradeBook's public
// interface without revealing the implementations of GradeBook's member
// functions, which are defined in GradeBook.cpp.
#include <string> // class GradeBook uses C++ standard string class
using std::string;
// GradeBook class definition
class GradeBook
{
public:
GradeBook( string, string ); // constructor that initializes courseName and
instructorName
void setCourseName( string ); // function that sets the course name
string getCourseName(); // function that gets the course name
void setInstructorName( string ); // function that sets the Instructor name
string getInstructorName(); // function that gets the Instructor name
void displayMessage(); // function that displays a welcome message
private:
string courseName; // course name for this GradeBook
string instructorName; // Instructor name for this GradeBook
}; // end class GradeBook
figure out where I am making a mistake. I can only imagine it is when I
declare multiple paramaters on the constructor because the program compiles
with just one parameter. Can someone look at this and tell me where I made
my error?
This is the error I get while trying to compile.
error C2664: 'GradeBook::GradeBook(const GradeBook &)' : cannot convert
parameter 1 from 'const char [38]' to 'const GradeBook &'
Reason: cannot convert from 'const char [38]' to 'const GradeBook'
No constructor could take the source type, or constructor overload
resolution was ambiguous
Thanks
// GradeBook.cpp
// GradeBook member-function definitions. This file contains
// implementations of the member functions prototyped in GradeBook.h.
#include <iostream>
using std::cout;
using std::endl;
#include "GradeBook.h" // include definition of class GradeBook
// constructor initializes courseName and instructorName with string
supplied as argument
GradeBook::GradeBook(string name, string instructor)
{
setCourseName( name ); // call set function to initialize courseName
setInstructorName( instructor );// call set function to initialize
instructorName
} // end GradeBook constructor
// function to set the course name
void GradeBook::setCourseName( string name )
{
courseName = name; // store the course name in the object
} // end function setCourseName
// function to get the course name
string GradeBook::getCourseName()
{
return courseName; // return object's courseName
} // end function getCourseName
// function to set the instructor name
void GradeBook::setInstructorName( string instructor )
{
instructorName = instructor; // store the instructor name in the object
} // end function setInstructorName
// function to get the instructor name
string GradeBook::getInstructorName()
{
return instructorName; // return object's instructorName
} // end function getInstructorName
// display a welcome message to the GradeBook user
void GradeBook::displayMessage()
{
// call getCourseName and getInstructorName to get the courseName and
instructorName
cout << "Welcome to the grade book for\n" << getCourseName()
<< "!" << endl;
cout << "This course is presented by:\n" << getInstructorName()
<< "!" << endl;
} // end function displayMessage
This is the header file
// GradeBook.h
// GradeBook class definition. This file presents GradeBook's public
// interface without revealing the implementations of GradeBook's member
// functions, which are defined in GradeBook.cpp.
#include <string> // class GradeBook uses C++ standard string class
using std::string;
// GradeBook class definition
class GradeBook
{
public:
GradeBook( string, string ); // constructor that initializes courseName and
instructorName
void setCourseName( string ); // function that sets the course name
string getCourseName(); // function that gets the course name
void setInstructorName( string ); // function that sets the Instructor name
string getInstructorName(); // function that gets the Instructor name
void displayMessage(); // function that displays a welcome message
private:
string courseName; // course name for this GradeBook
string instructorName; // Instructor name for this GradeBook
}; // end class GradeBook