By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,134 Members | 1,742 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,134 IT Pros & Developers. It's quick & easy.

Constructor Syntax Problem

P: n/a
Hello,

I'm working my way through Bruce Eckel's Thinking in C++ and I've run
into a small problem. This code is from his book:

class Fi
{
public:
Fi( ) { }
};

class Fee
{
public:
Fee(int) { }
Fee(const fi&) { }
};

int main( )
{
Fee fee = 1;
Fi fi;
Fee fum = fi;
}

He claims this should all work but my compiler complains as follows:

ex19.cpp:11: parse error before '&'
ex19.cpp:11: missing ';' before right brace
ex19.cpp:12: parse error at null character
ex19.cpp: In function 'int main( )':
ex19.cpp:18: conversion from 'Fi' to non-sclaler type 'Fee' requested.

So, what gives? Is his text wrong or is my compiler broke? By the way
the compiler is gcc 2.96

Thanks in advance for any replies!

-exits

Jul 22 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"exits funnel" <ex*********@NOSPAMyahoo.com> wrote...
I'm working my way through Bruce Eckel's Thinking in C++ and I've run
into a small problem. This code is from his book:

class Fi
{
public:
Fi( ) { }
};

class Fee
{
public:
Fee(int) { }
Fee(const fi&) { }
Are you sure that the book doesn't in fact have

Fee(const Fi&) { }

? C++ is case-sensitive language, you know.
};

int main( )
{
Fee fee = 1;
Fi fi;
Fee fum = fi;
}

He claims this should all work but my compiler complains as follows:

ex19.cpp:11: parse error before '&'
ex19.cpp:11: missing ';' before right brace
ex19.cpp:12: parse error at null character
ex19.cpp: In function 'int main( )':
ex19.cpp:18: conversion from 'Fi' to non-sclaler type 'Fee' requested.

So, what gives? Is his text wrong or is my compiler broke?
Re-typing from a book is the an exercise in frustration. Try to
find the electronic version of the book's example code.
By the way
the compiler is gcc 2.96


Victor
Jul 22 '05 #2

P: n/a
exits funnel wrote:
Hello,

I'm working my way through Bruce Eckel's Thinking in C++ and I've run
into a small problem. This code is from his book:

class Fi
{
public:
Fi( ) { }
};

class Fee
{
public:
Fee(int) { }
Fee(const fi&) { } ITYM:
Fee(const Fi&) { }
};

int main( )
{
Fee fee = 1;
Fi fi;
Fee fum = fi;
}

He claims this should all work but my compiler complains as follows:

ex19.cpp:11: parse error before '&'
ex19.cpp:11: missing ';' before right brace
ex19.cpp:12: parse error at null character
ex19.cpp: In function 'int main( )':
ex19.cpp:18: conversion from 'Fi' to non-sclaler type 'Fee' requested.

So, what gives? Is his text wrong or is my compiler broke? By the way
the compiler is gcc 2.96


Erm, please see the typo indicated above.
(But I do strongly suggest upgrading to a more recent gcc, which
would be much closer to conforming to the standard.)

HTH,
--ag

--
Artie Gold -- Austin, Texas
Oh, for the good old days of regular old SPAM.

Jul 22 '05 #3

P: n/a

"exits funnel" <ex*********@NOSPAMyahoo.com> wrote in message
news:3F**************@NOSPAMyahoo.com...
Hello,

I'm working my way through Bruce Eckel's Thinking in C++ and I've run
into a small problem. This code is from his book:

class Fi
{
public:
Fi( ) { }
};

class Fee
{
public:
Fee(int) { }
Fee(const fi&) { }
};

int main( )
{
Fee fee = 1;
Fi fi;
Fee fum = fi;
}

He claims this should all work but my compiler complains as follows:

ex19.cpp:11: parse error before '&'
ex19.cpp:11: missing ';' before right brace
ex19.cpp:12: parse error at null character
ex19.cpp: In function 'int main( )':
ex19.cpp:18: conversion from 'Fi' to non-sclaler type 'Fee' requested.

So, what gives? Is his text wrong or is my compiler broke?


There is a third option you know - you didn't type it in exactly like it was
in the book.
Jul 22 '05 #4

P: n/a
jeffc wrote:
"exits funnel" <ex*********@NOSPAMyahoo.com> wrote in message
news:3F**************@NOSPAMyahoo.com...
Hello,

I'm working my way through Bruce Eckel's Thinking in C++ and I've run
into a small problem. This code is from his book:

class Fi
{
public:
Fi( ) { }
};

class Fee
{
public:
Fee(int) { }
Fee(const fi&) { }
};

int main( )
{
Fee fee = 1;
Fi fi;
Fee fum = fi;
}

He claims this should all work but my compiler complains as follows:

ex19.cpp:11: parse error before '&'
ex19.cpp:11: missing ';' before right brace
ex19.cpp:12: parse error at null character
ex19.cpp: In function 'int main( )':
ex19.cpp:18: conversion from 'Fi' to non-sclaler type 'Fee' requested.

So, what gives? Is his text wrong or is my compiler broke?

There is a third option you know - you didn't type it in exactly like it was
in the book.


Hint to OP: C++ is case sensitive.

Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.