473,405 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Constructor Syntax Problem

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
4 2461
"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
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

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
by: Andy | last post by:
1) Is there any use of defining a class with a single constructor declared in private scope? I am not asking a about private copy constructors to always force pass/return by reference. 2) Is...
23
by: Fabian Müller | last post by:
Hi all, my question is as follows: If have a class X and a class Y derived from X. Constructor of X is X(param1, param2) . Constructor of Y is Y(param1, ..., param4) .
26
by: Paul | last post by:
public class A { public A () { // here I would like to call the second version of _ctor, how to accomplish this ? } public A (int a, int b, int c) {
12
by: Edward Diener | last post by:
Given value class X { public: // Not allowed: X():i(100000),s(10000) { } // Allowed void InitializeDefaults() { i = 100000; s = 10000; } private: int i;
6
by: daveb | last post by:
I'm trying to write some code that calls the constructors of STL containers explicitly, and I can't get it to compile. A sample program is below. One compiler complains about the last two lines...
9
by: toton | last post by:
Hi, Which one is the correct syntax for constructor for static memory allocation Object obj("param"); or Object obj = Object("param"); 1) For the first one, how compiler checks it as not a...
23
by: TarheelsFan | last post by:
What happens whenever you throw an exception from within a constructor? Does the object just not get instantiated? Thanks for replies.
74
by: Zytan | last post by:
I have a struct constructor to initialize all of my private (or public readonly) fields. There still exists the default constructor that sets them all to zero. Is there a way to remove the...
12
by: Rahul | last post by:
Hi Everyone, I have the following code and i'm able to invoke the destructor explicitly but not the constructor. and i get a compile time error when i invoke the constructor, why is this so? ...
3
by: willo | last post by:
Greetings all, I have run into a small problem with my understanding of some C++ language syntax, and seek some clarification. Below is a condensed version of some code I'm having difficulty...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.