Constructor Syntax Problem

E

exits funnel

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
 
V

Victor Bazarov

exits funnel said:
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
 
A

Artie Gold

exits said:
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
 
J

jeffc

exits funnel said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,147
Messages
2,570,833
Members
47,380
Latest member
AlinaBlevi

Latest Threads

Top