Wrox Programmer Forums
|
BOOK: Ivor Horton's Beginning Visual C++ 2005
This is the forum to discuss the Wrox book Ivor Horton's Beginning Visual C++ 2005 by Ivor Horton; ISBN: 9780764571978
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Ivor Horton's Beginning Visual C++ 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 27th, 2007, 05:53 PM
Authorized User
 
Join Date: Dec 2006
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default beginner C++ question p62

in discussing enum's, the example for a bool enum is given

enum State : bool { On = true, Off};

I get this error when I include this line in my main() function:
Error 1 error C3168: 'bool' : illegal underlying type for enum c:\documents and settings\<user snipped>\my documents\visual studio 2005\projects\c++\ex2_01a\ex2_01a\ex2_01a.cpp 20

Here's my MFC Console .cpp file:

#include "stdafx.h"
#include <iostream>
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{

enum State : bool {On=true, Off} myState;
myState = On;

//I try the std::cout line below, but it's not in the book
//but my compile error is on the "enum State : bool" line

std::cout << "state = " << (int)myState << std::endl;

return 0;
}



Sincerely,
Brian
__________________
Sincerely,
Brian
 
Old January 30th, 2007, 05:24 PM
Authorized User
 
Join Date: May 2006
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

See your problem -i.e. I can duplicate it, but have not found a solution. I suggest emailing the author -and please post answer.

 
Old February 1st, 2007, 03:53 PM
Authorized User
 
Join Date: Dec 2006
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't know how to reach the author. Does Ivor state in the book that he is open to comments / questions?




Sincerely,
Brian
 
Old February 2nd, 2007, 02:13 AM
Authorized User
 
Join Date: May 2006
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Go to http://www.wrox.com/WileyCDA/WroxTit...ew_errata.html

and fill in the form at
http://wrox.custhelp.com/cgi-bin/wro...nduser/ask.php

Btw the Errata page, linked to above, now lists some corrections.

Edit:
You may find the following Visual Studio forum useful, especially for the above problem.
http://forums.microsoft.com/msdn/sho...id=29&siteid=1
 
Old February 7th, 2007, 04:23 PM
Authorized User
 
Join Date: Dec 2006
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I contacted Wiley/Wrox about this, and they got this feedback from the auther, Ivor Horton.

Per the author:

>>The example on P. 62 is not correct. The enum with type bool enumerators should be:

enum State : bool {On=true, Off=false};

The original fragment used to compile but the compiler was ultimately modified to enforce the rule that enumerators in an enum of type bool must all be explicitly initialized. C++/CLI enums of other explicit types do not need to be initialized explicitly, although they can be.

Note that the section "Specifying the Type for Enumeration Constants" is misplaced and should be a subsection of the "C++/CLI Programming" section as it is specific to C++/CLI.Regular C++ only supports enums with an implicit integral type for the enumerators.<<


Sincerely,
Brian





Similar Threads
Thread Thread Starter Forum Replies Last Post
xslt beginner question cfflexguy XSLT 4 October 16th, 2007 09:11 AM
Beginner Question dkr72 Excel VBA 1 January 18th, 2005 09:37 AM
Beginner question on getting only certain elements EstherMStrom XSLT 5 December 10th, 2004 04:38 PM
beginner question saudyonline General .NET 2 September 21st, 2004 01:56 AM
Stupid Question from a BEGINNER Shappy Access VBA 1 May 11th, 2004 03:32 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.