Wrox Programmer Forums
| 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 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 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.
 
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?
 
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
 
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.




Similar Threads
Thread Thread Starter Forum Replies Last Post
Code to save html page source code? Jaymond Flurrie Access VBA 2 July 2nd, 2019 06:04 PM
DataList is Showing Up in Source Code, But Not On Web Page? kwilliams ASP.NET 3.5 Basics 10 January 20th, 2016 02: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 03:16 PM
Highlighted code; Page 1113, Ch 22 Nick Y BOOK: Ivor Horton's Beginning Visual C++ 2005 0 August 4th, 2006 10:13 AM





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