Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > BOOK: Ivor Horton's Beginning Visual C++ 2005
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 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 July 10th, 2006, 09:59 AM
Authorized User
Join Date: May 2006
Location: Iver, Bucks., United Kingdom.
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default LinkedList<T>, AddTail, EX9_22, pages 557-559

An error caused by use of AddTail(), which I think can only be used with integers.
The following is returned when compiling EX9_22:

error C2039: 'AddTail' : is not a member of 'System::Collections::Generic::LinkedList<T>'

The solution is to replace AddTail() with AddLast()

AddTail is in the 'Code from the book' and hence EX9_22 fails to compile.

Hence: Page 557 would appear to be incorrect with regards references to both AddHead() and AddTail(), which require integers. Replace respectively with AddFirst() and AddLast() for doubles.

You could add values to the list like this:

       for(int i = 0 ; i<1000 ; i++)

The AddLast() function adds an item to the end of the list. You can add items to the beginning of the list by using the AddFirst() function. Alternatively, you can use the AddHead() and AddTail() functions
to do the same things.

Page 559 (EX9_22)
Change from

// Using LinkedList<T>
  Console::WriteLine(L"\nCreating a LinkedList<T> of double values:");
  LinkedList<double>^ values = gcnew LinkedList<double>;
  for(int i = 0 ; i<1000 ; i++)


 // Using LinkedList<T>
  Console::WriteLine(L"\nCreating a LinkedList<T> of double values:");
  LinkedList<double>^ values = gcnew LinkedList<double>;
  for(int i = 0 ; i<1000 ; i++)


Additionally: Page 561, third paragraph should replace AddTail() with AddLast() and hence ignore the sentence following ('You could equally well use the AddLast() function to do the same thing.')
  #2 (permalink)  
Old January 26th, 2010, 07:03 PM
Authorized User
Join Date: Jan 2010
Posts: 27
Thanks: 2
Thanked 0 Times in 0 Posts
Red face error C2248

I get this error for the following code and would like to know what's wrong I'm using standard 2008

Error 1 error C2248: 'System::Collections::Generic::Dictionary<TKey,TVa lue>::values' : cannot access private member declared in class 'System::Collections::Generic::Dictionary<TKey,TVa lue>' c:\Users\Dan\Documents\Visual Studio 2008\Projects\Chapter9\Ex9_22a\Ex9_22a\Ex9_22a.cpp 90 Ex9_22a

// Ex9_22.cpp : main project file.
// Using generic collection classes

#include "stdafx.h"

using namespace System;
using namespace System::Collections::Generic;		//For generic collections

//class encapsulating a name
ref class Name
	Name(String^ name1, String^ name2) : First(name1), Second(name2){}
	virtual String^ ToString() override
		return First + L" " + Second;
	String^ First;
	String^ Second;

//Class encapsulating a phone number
ref class PhoneNumber
	PhoneNumber(int area, int local, int number):
	  Area(area), Local(local), Number(number) {}
	 virtual String^ ToString() override
		 return Area + L" " + Local + L" " + Number;

	int Area;
	int Local;
	int Number;

int main(array<System::String ^> ^args)
    //Using List<T>
	Console::WriteLine(L"Creating a List<T> of integers:");
	List<int>^ numbers = gcnew List<int>;
	for( int i = 0 ; i < 1000; i++)

	//Sum the contents of the list
	int sum = 0;
	for(int i = 0; i < numbers->Count; i++)
		sum += numbers[i];
	Console::WriteLine(L"Total = {0}", sum);

	//Using LinkedList<T>
	Console::WriteLine(L"\nCreating a LinkedList<T> of double values:");
	LinkedList<double>^ values = gcnew LinkedList<double>;
	for(int i = 0; i < 1000; i++)

	double sumd = 0.0;
	for each(double v in values)
		sumd += v;

	Console::WriteLine(L"Total = {0}", sumd);

	LinkedListNode<double>^ node = values->Find(20.0);		//Find node containing 20.0
	values->AddBefore(node, 19.9);
	values->AddAfter(values->Find(30.0), 30.1);

	//Sum the contents of the linked list again
	sumd = 0.0;
	for each(double v in values)
		sumd += v;

	Console::WriteLine(L"Total after adding values = {0}", sumd);

	//Using Dictionary<K,V>
	Console::WriteLine(L"\nCreating a Dictionary<K,V> of name/number pairs:");
	Dictionary<Name^, PhoneNumber^>^ phonebook = gcnew Dictionary<Name^, PhoneNumber^>;

	//Add name/number pairs to dictionary
	Name^ name = gcnew Name("Jim", "Jones");
	PhoneNumber^ number = gcnew PhoneNumber(914, 316, 2233);
	phonebook->Add(name, number);
	phonebook->Add(gcnew Name("Fred", "Fong"), gcnew PhoneNumber(123, 234, 3456));
	phonebook->Add(gcnew Name("Janet", "Smith"), gcnew PhoneNumber(515, 224,6864));

	//List all numbers
	Console::WriteLine(L"List all the numbers:");
	for each(PhoneNumber^ number in phonebook->values)

	//List all names and numbers
	Console::WriteLine(L"Access the keys to list all name/number pairs:");
	for each(Name^ name in phonebook->Keys)
		Console::WriteLine(L"{0} : {1}", name, phonebook[name]);

    return 0;

Last edited by abilify; January 26th, 2010 at 07:08 PM.

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
Ch 8: <asp:image> inside <a> & ext.CSS (pg. 274) epc BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 July 12th, 2008 05:37 AM
<style> tags in a <body> vs. <div> bcat BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 1 March 27th, 2005 08:50 AM
<marquee><b>About CHAT App. in PHP4</b></marquee> Ramkrishna PHP How-To 1 September 11th, 2004 08:01 AM
<STRONG> vs <B> and <EM> vs <I> anshul HTML Code Clinic 12 September 1st, 2004 06:22 PM
a problem in book<<beginning asp.net using vb>> luoware ASP.NET 1.0 and 1.1 Basics 3 December 8th, 2003 09:32 PM

All times are GMT -4. The time now is 01:40 PM.

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