Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional C++, 2nd Edition
This is the forum to discuss the Wrox book Professional C++, 2nd Edition by Marc Gregoire, Nicholas A. Solter, Scott J. Kleper ; ISBN: 978-1-1181-6995-7
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional C++, 2nd Edition section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 21st, 2012, 08:08 PM
Authorized User
Points: 50, Level: 1
Points: 50, Level: 1 Points: 50, Level: 1 Points: 50, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2011
Posts: 12
Thanks: 5
Thanked 0 Times in 0 Posts
Default Page 22 Source Code

The little piece of code on page 22 does not seem to work in VC++11 but produces no errors in VC++10. In VC++11, it is saying that the i defined with the auto needs an initializer. VC++10 does not produce that error.
  #2 (permalink)  
Old April 22nd, 2012, 03:52 AM
Wrox Author
Points: 220, Level: 4
Points: 220, Level: 4 Points: 220, Level: 4 Points: 220, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2011
Posts: 49
Thanks: 0
Thanked 4 Times in 4 Posts
Default

There is a small misprint, which should appear on the books' errata page, but it's not there yet.

I just tried the following code in Visual C++ 11 Beta and it works correctly:
Code:
#include <iostream>
#include <array>

using namespace std;

int main()
{
	array<int, 3> arr = {9, 8, 7};
	cout << "Array size = " << arr.size() << endl;
	for (auto i : arr)
		cout << i << endl;

	return 0;
}
Is this piece of code giving an error when you try it?
  #3 (permalink)  
Old April 22nd, 2012, 12:25 PM
Authorized User
Points: 50, Level: 1
Points: 50, Level: 1 Points: 50, Level: 1 Points: 50, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2011
Posts: 12
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Hi Marc,
This is truly odd. When I Build it, it says down at the bottom left that it succeeded. However, on the line of the 'for loop' there are 3 small seperate squiggly lines. One under the 'i', one under the colon, and one under the right parenthesis. Here are the error messages I'm getting at the bottom. (Sorry if their not formatted correctly.)

Quote:
1 IntelliSense: cannot deduce 'auto' type (initializer required) c:\Users\Bob\Documents\Visual Studio 11\Projects\test\test\Source.cpp 10 12 test
2 IntelliSense: expected a ';' c:\Users\Bob\Documents\Visual Studio 11\Projects\test\test\Source.cpp 10 14 test
3 IntelliSense: expected an expression c:\Users\Bob\Documents\Visual Studio 11\Projects\test\test\Source.cpp 10 19 test
  #4 (permalink)  
Old April 22nd, 2012, 12:41 PM
Wrox Author
Points: 220, Level: 4
Points: 220, Level: 4 Points: 220, Level: 4 Points: 220, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2011
Posts: 49
Thanks: 0
Thanked 4 Times in 4 Posts
Default

That's the IntelliSense.
IntelliSense still has a problem with correctly parsing the range-based for loop, and thus shows you red squiggly lines.
However, the real VC++ compiler understands range-based for loops perfectly fine, as you can see in your case where it says "succeeded". After compiling, just try to execute your program, and you'll see it's working correctly, even with the red squiggles.
This is a know issue with IntelliSense, and Microsoft is working on it.
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
DataList is Showing Up in Source Code, But Not On Web Page? kwilliams ASP.NET 3.5 Basics 10 January 20th, 2016 01:15 PM
Page 6 Source Code charles724 BOOK: Beginning JavaScript and CSS Development with jQuery 3 April 28th, 2011 05:50 AM
Page 22 XML in French wnazzaro BOOK: Beginning XML, 4th Ed ISBN: 978-0-470-11487-2 3 January 28th, 2009 02:16 PM
Code to save html page source code? Jaymond Flurrie Access VBA 1 December 18th, 2008 09:28 AM
Highlighted code; Page 1113, Ch 22 Nick Y BOOK: Ivor Horton's Beginning Visual C++ 2005 0 August 4th, 2006 10:13 AM



All times are GMT -4. The time now is 03:06 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.