473,668 Members | 2,261 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help Code won't compile

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::Gra deBook(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::Grad eBook(string name, string instructor)

{

setCourseName( name ); // call set function to initialize courseName

setInstructorNa me( instructor );// call set function to initialize
instructorName

} // end GradeBook constructor

// function to set the course name

void GradeBook::setC ourseName( string name )

{

courseName = name; // store the course name in the object

} // end function setCourseName

// function to get the course name

string GradeBook::getC ourseName()

{

return courseName; // return object's courseName

} // end function getCourseName

// function to set the instructor name

void GradeBook::setI nstructorName( string instructor )

{

instructorName = instructor; // store the instructor name in the object

} // end function setInstructorNa me

// function to get the instructor name

string GradeBook::getI nstructorName()

{

return instructorName; // return object's instructorName

} // end function getInstructorNa me

// display a welcome message to the GradeBook user

void GradeBook::disp layMessage()

{

// call getCourseName and getInstructorNa me to get the courseName and
instructorName

cout << "Welcome to the grade book for\n" << getCourseName()

<< "!" << endl;

cout << "This course is presented by:\n" << getInstructorNa me()

<< "!" << 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 setInstructorNa me( string ); // function that sets the Instructor name

string getInstructorNa me(); // 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



Jun 30 '06 #1
10 2024
B Williams wrote:
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::Gra deBook(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

Somewhere you are attempting to copy a GradeBook object and you don't
have a copy constructor.

A couple points of style:

Way way too many superfluous comments. Just give things meaningful
names and let the code tell its own story.

Never ever put a using directive in a header.

--
Ian Collins.
Jun 30 '06 #2
B Williams wrote:
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::Gra deBook(const GradeBook &)' : cannot
convert parameter 1 from 'const char [38]' to 'const GradeBook &'

Reason: cannot convert from 'const char [38]' to 'const GradeBook'
Which line of the code you have posted does this message relate to?

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::Grad eBook(string name, string instructor)

{

setCourseName( name ); // call set function to initialize courseName

setInstructorNa me( instructor );// call set function to initialize
instructorName

} // end GradeBook constructor

// function to set the course name

void GradeBook::setC ourseName( string name )

{

courseName = name; // store the course name in the object

} // end function setCourseName

// function to get the course name

string GradeBook::getC ourseName()

{

return courseName; // return object's courseName

} // end function getCourseName

// function to set the instructor name

void GradeBook::setI nstructorName( string instructor )

{

instructorName = instructor; // store the instructor name in the
object
} // end function setInstructorNa me

// function to get the instructor name

string GradeBook::getI nstructorName()

{

return instructorName; // return object's instructorName

} // end function getInstructorNa me

// display a welcome message to the GradeBook user

void GradeBook::disp layMessage()

{

// call getCourseName and getInstructorNa me to get the courseName and
instructorName

cout << "Welcome to the grade book for\n" << getCourseName()

<< "!" << endl;

cout << "This course is presented by:\n" << getInstructorNa me()

<< "!" << 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 setInstructorNa me( string ); // function that sets the
Instructor name
string getInstructorNa me(); // 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


V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 30 '06 #3
B Williams wrote:
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?


Please read the FAQ for this newsgroup, specifically the section on how
to post. You need to post complete, compilable, minimal code which
illustrates the problem. The code you posted does not even include a
main() function. I took the time to read through it in spite of this
and do not think you've posted the line of code which is causing the
error. It would be helpful if you identified which line the error was
talking about, too.

Also, I concur with the other poster regarding your use of comments --
a comment which does nothing more than state something like "call
getFoo to get the Foo" is worse than useless. I'll further add that
having getFoo() and setFoo() for your private Foo member is essentially
no better in terms of design than just making that member public, but
you'll have time to appreciate such design subtleties after you've
gained more mastery of the language fundamentals.

Luke

Jun 30 '06 #4
This is the code that contains the main. The error is occuring at both of
these lines.

GradeBook courseName( "CS101 Introduction to C++ Programming" );

GradeBook instructorName( "Mr Johnson");
#include <iostream>

using std::cout;

using std::endl;

#include "GradeBook. h" // include definition of class GradeBook

// function main begins program execution

int main()

{

// create two GradeBook objects

GradeBook courseName( "CS101 Introduction to C++ Programming" );

GradeBook instructorName( "Mr Johnson");

// display initial value of courseName for each GradeBook

cout << "gradeBook1 created for course: " << courseName.getC ourseName()

<< "\nThe instructor for this course is: " <<
instructorName. getInstructorNa me()

<< endl;

return 0; // indicate successful termination

} // end main

"Victor Bazarov" <v.********@com Acast.net> wrote in message
news:e8******** **@news.datemas .de...
B Williams wrote:
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::Gra deBook(const GradeBook &)' : cannot
convert parameter 1 from 'const char [38]' to 'const GradeBook &'

Reason: cannot convert from 'const char [38]' to 'const GradeBook'


Which line of the code you have posted does this message relate to?

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::Grad eBook(string name, string instructor)

{

setCourseName( name ); // call set function to initialize courseName

setInstructorNa me( instructor );// call set function to initialize
instructorName

} // end GradeBook constructor

// function to set the course name

void GradeBook::setC ourseName( string name )

{

courseName = name; // store the course name in the object

} // end function setCourseName

// function to get the course name

string GradeBook::getC ourseName()

{

return courseName; // return object's courseName

} // end function getCourseName

// function to set the instructor name

void GradeBook::setI nstructorName( string instructor )

{

instructorName = instructor; // store the instructor name in the
object
} // end function setInstructorNa me

// function to get the instructor name

string GradeBook::getI nstructorName()

{

return instructorName; // return object's instructorName

} // end function getInstructorNa me

// display a welcome message to the GradeBook user

void GradeBook::disp layMessage()

{

// call getCourseName and getInstructorNa me to get the courseName and
instructorName

cout << "Welcome to the grade book for\n" << getCourseName()

<< "!" << endl;

cout << "This course is presented by:\n" << getInstructorNa me()

<< "!" << 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 setInstructorNa me( string ); // function that sets the
Instructor name
string getInstructorNa me(); // 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


V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

Jul 1 '06 #5
Thanks guys,
I included the code that included the main. What is really confusing me is
that if I remove all lines refering to the instructor, it compiles fine.

Thanks again for your assistance.

"Luke Meyers" <n.***********@ gmail.com> wrote in message
news:11******** **************@ y41g2000cwy.goo glegroups.com.. .
B Williams wrote:
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?


Please read the FAQ for this newsgroup, specifically the section on how
to post. You need to post complete, compilable, minimal code which
illustrates the problem. The code you posted does not even include a
main() function. I took the time to read through it in spite of this
and do not think you've posted the line of code which is causing the
error. It would be helpful if you identified which line the error was
talking about, too.

Also, I concur with the other poster regarding your use of comments --
a comment which does nothing more than state something like "call
getFoo to get the Foo" is worse than useless. I'll further add that
having getFoo() and setFoo() for your private Foo member is essentially
no better in terms of design than just making that member public, but
you'll have time to appreciate such design subtleties after you've
gained more mastery of the language fundamentals.

Luke

Jul 1 '06 #6
B Williams wrote:
This is the code that contains the main. The error is occuring at
both of these lines.

GradeBook courseName( "CS101 Introduction to C++ Programming" );

GradeBook instructorName( "Mr Johnson");
[..]


Your class 'GradeBook' has a constructor that takes 2 strings. You
only provide a single string literal in both of those cases.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 1 '06 #7
B Williams schrieb:
This is the code that contains the main. The error is occuring at both of
these lines.

GradeBook courseName( "CS101 Introduction to C++ Programming" );

GradeBook instructorName( "Mr Johnson");


[snipped some code]

Why do you write a class, that holds a course name and an instructor
name and then instantiate two objects, one using only the course name
and the other using only the instructor name?

Thats like buying two cars: one to get to work, one to get home.

Another thing: Do you know about whitespaces and indentation? Its very
usefull to understand your code.

Thomas
Jul 1 '06 #8
B Williams wrote:
Thanks guys,
I included the code that included the main. What is really confusing me is
that if I remove all lines refering to the instructor, it compiles fine.

Thanks again for your assistance.


You're welcome. As others have indicated, the problem is that you're
not calling your constructor correctly. Your constructor is declared
with two arguments, so you must pass two arguments (of appropriate
types).

Also, don't top-post.

Also, though it was entirely obvious, when asking for help with
homework you should explicitly state that this is the case, to avoid
the appearance of impropriety and the chance that someone will provide
so much information that you fail to learn what you're supposed to.

Luke

Jul 1 '06 #9
I would like to thank everyone for their assistance. I didn't know the rules
to this news group. I would really like to read them because taking an
online programming class can be painful when you try to ask for assistance
and have to wait hours/days for the instructor to respond. I have corrected
my code to pass two arguments. It now compiles. I am off to the next
program.

"Luke Meyers" <n.***********@ gmail.com> wrote in message
news:11******** **************@ d56g2000cwd.goo glegroups.com.. .
B Williams wrote:
Thanks guys,
I included the code that included the main. What is really confusing me
is
that if I remove all lines refering to the instructor, it compiles fine.

Thanks again for your assistance.


You're welcome. As others have indicated, the problem is that you're
not calling your constructor correctly. Your constructor is declared
with two arguments, so you must pass two arguments (of appropriate
types).

Also, don't top-post.

Also, though it was entirely obvious, when asking for help with
homework you should explicitly state that this is the case, to avoid
the appearance of impropriety and the chance that someone will provide
so much information that you fail to learn what you're supposed to.

Luke

Jul 1 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
5464
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I debug it in PHP designer, it works with no problems, I get the test email. If
13
6207
by: webzila | last post by:
Hello, I have to write a program for an 8051 micro-controller using micro-C to monitor Switch 1 and if the switch in pushed the message "switch 1 pushed" should be displayed in the LCD. Also the microcontroller should display in the LCD the value of the voltage applied to the input of the ADC. The above procedure should only execute once the user has entered "1234" using a keypad that is attached to the 8051 microprocessor.
5
6746
by: n_o_s_p_a__m | last post by:
Can't compile. Does this mean that all functions that throw exceptions must be of return type void? examples: // won't compile: "not all code paths return a value" public override int Run() { throw new Exception("exception thrown"); }
18
2445
by: Euphor2 | last post by:
I'm in school, taking a VB .NET 2003 course, and the teacher taught us how to use Sender.Focus() to return focus to the control from which focus was received. However, when I got home, and tried it on my own copy of VB .NET 2003, it doesn't seem to work, in fact the only method that comes up with Intellisense is GetType. I can't find any information anywhere either in the MSDN Library, or anywhere else for that matter. I was hoping...
22
2119
by: macAWM | last post by:
Hi list, First let me explain that my background is in Java and I am quite spoiled to its niceties (read "less ambiguous nature"). Anyway to my problems. 1. I want to write my own library for what I consider to be some holes in the standard language. How do I go about writing and compiling this without this stupid error about not having a 'main' function. I don't want a stupid 'main' function. (I'm compiling using gcc 4.0.) I would...
8
2092
by: novice | last post by:
Hi geeks, Can any body explain me how to analyse int the pollowing code This is the question I was asked in the interview... char *s ={ "hello", "basic", "world", "program"}; char **sPtr = { s+3, s+2, s+1, s };
10
1826
by: Sourcerer | last post by:
I wrote this very simple code in .NET VC++. I compiled it on my system, and tried to run it on my friend's computer (he doesn't have the compiler). We both have Windows XP Professional. I have .NET framework 2.0, and he had 1.0 and it didn't work; then he installed 2.0 and it still didn't work; so he tried with 2.1 and it didn't work, then 3.0 and nothing still worked. I have Intel Centrino Mobile (laptop computer), and he has Intel Pentium...
8
2321
by: mohammaditraders | last post by:
#include <iostream.h> #include <stdlib.h> #include <conio.h> #include <string.h> class Matrix { private : int numRows, numCols ; int elements ;
5
5957
by: DaveD | last post by:
Can anyone help me get this compiled ? void Write<T>(T val) { byte bytes = BitConverter.GetBytes(val); Array.Reverse(bytes); writer.Write(bytes); } The problem is that for T=bool, BitConverter.GetBytes(bool) won't compile. In C++ I would have created an explicit instantiation like
0
8459
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8374
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8791
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7398
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6206
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5677
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4373
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2018
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1783
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.