Wrox Programmer Forums
|
BOOK: Beginning Visual C# 2010
This is the forum to discuss the Wrox book Beginning Visual C# 2010 by Karli Watson, Christian Nagel, Jacob Hammer Pedersen, Jon D. Reid, Morgan Skinner, ; ISBN: 9780470502266
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual C# 2010 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 November 15th, 2011, 09:33 PM
Authorized User
 
Join Date: Nov 2011
Posts: 34
Thanks: 14
Thanked 0 Times in 0 Posts
Default Chapter 11 Deep Clone,page 301

This code:

namespace ClassLibrary1
{
public class content:ICloneable
{
public int val;
}

public class cloner:ICloneable
{
public content mycontent = new content();

public cloner(int newval)
{
mycontent.val = newval;
}


public object clone()
{
cloner clonedcloner=new cloner();
return clonedcloner.mycontent.Clone();
return clonedcloner;
}


Throw next errors:


-ClassLibrary1.cloner does not contain a constructor that takes 0 arguments


-ClassLibrary1.content' does not contain a definition for 'Clone' and no extension method 'Clone' accepting a first argument of type 'ClassLibrary1.content' could be found (are you missing a using directive or an assembly reference?)


What i am doing wrong?
 
Old November 19th, 2011, 04:02 PM
Wrox Author
 
Join Date: Sep 2010
Posts: 175
Thanks: 3
Thanked 53 Times in 53 Posts
Default

Quote:
Originally Posted by dampyr View Post
This code:
Code:
namespace ClassLibrary1
{
    public class content:ICloneable
    {
        public int val;
    }

    public class cloner:ICloneable
    {
        public content mycontent = new content();

        public cloner(int newval)
        {
            mycontent.val = newval;
        }
   
        
            public object clone()
       {
            cloner clonedcloner=new cloner();
            return clonedcloner.mycontent.Clone();
            return clonedcloner;
            }
Throw next errors:


-ClassLibrary1.cloner does not contain a constructor that takes 0 arguments


-ClassLibrary1.content' does not contain a definition for 'Clone' and no extension method 'Clone' accepting a first argument of type 'ClassLibrary1.content' could be found (are you missing a using directive or an assembly reference?)


What i am doing wrong?
Within the clone method you cread a cloner with new cloner() - using a constructor with 0 arguments. The cloner class, however, defines a constructor that requires 1 argument of type int.
__________________
Christian
CN innovation
Visit my blog at: csharp.christiannagel.com
Follow me on twitter: @christiannagel
The Following User Says Thank You to ChristianNagel For This Useful Post:
dampyr (November 20th, 2011)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 9 - Page 301 Try it Out demac3 BOOK: Beginning ASP.NET 4 : in C# and VB 7 December 9th, 2010 02:47 PM
CH 12 page 301 (overloaded method) jon4554 BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 1 March 2nd, 2010 03:02 PM
Chapter 11 Page 354 skijor BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 6 August 9th, 2009 08:02 AM
Chapter 1, page 11 typo? tumana BOOK Beginning Linux Programming, 3rd Edition 4 August 25th, 2006 10:43 AM





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