COpy object

Discussion in 'C++' started by Joe Cipale, May 20, 2004.

  1. Joe Cipale

    Joe Cipale Guest

    I have a class defined as follows:
    public:
    char Date[2 * BYTE];
    char weight[6];
    char Workout[2 * BYTE];
    char Event[64];

    TDaily* nxt_Daily;

    I have defined my constructor/copy methods as shown:

    TDaily* init_date(TDaily **pDaily);
    TDaily* Copy(const TDaily &copy); // Copy constructor
    void operator=(const TDaily &copy);

    I try to use my copy constructor in my program as below:
    TDaily bfr_date = tmp;

    I get the following error:
    Settings.cpp: In method `class TDaily * TDaily::Edit_date(TDaily **,
    TBike *)':
    Settings.cpp:698: conversion from `TDaily *' to non-scalar type `TDaily'
    requested

    I do not see where my fubar is... any ideas?

    Joe

    #----------------------------------------------------------#
    # Penguinix Consulting #
    #----------------------------------------------------------#
    # Software development, QA and testing. #
    # Linux support and training. #
    # "Don't fear the penguin!" #
    #----------------------------------------------------------#
    # Registered Linux user: #309247 http://counter.li.org #
    #----------------------------------------------------------#
     
    Joe Cipale, May 20, 2004
    #1
    1. Advertising

  2. Joe Cipale wrote:
    > I have a class defined as follows:
    > public:
    > char Date[2 * BYTE];
    > char weight[6];
    > char Workout[2 * BYTE];
    > char Event[64];
    >
    > TDaily* nxt_Daily;
    >
    > I have defined my constructor/copy methods as shown:
    >
    > TDaily* init_date(TDaily **pDaily);
    > TDaily* Copy(const TDaily &copy); // Copy constructor
    > void operator=(const TDaily &copy);
    >
    > I try to use my copy constructor in my program as below:
    > TDaily bfr_date = tmp;
    >
    > I get the following error:
    > Settings.cpp: In method `class TDaily * TDaily::Edit_date(TDaily **,
    > TBike *)':
    > Settings.cpp:698: conversion from `TDaily *' to non-scalar type `TDaily'
    > requested
    >
    > I do not see where my fubar is... any ideas?


    Post real code. And make it complete and compilable this time.

    V
     
    Victor Bazarov, May 21, 2004
    #2
    1. Advertising

  3. Joe Cipale

    David Harmon Guest

    On Thu, 20 May 2004 15:20:02 -0700 in comp.lang.c++, Joe Cipale <> wrote,
    > TDaily* Copy(const TDaily &copy); // Copy constructor


    That is no copy constructor.
     
    David Harmon, May 21, 2004
    #3
  4. Joe Cipale

    Joe Cipale Guest

    Victor Bazarov wrote:
    >
    > Joe Cipale wrote:
    > > I have a class defined as follows:
    > > public:
    > > char Date[2 * BYTE];
    > > char weight[6];
    > > char Workout[2 * BYTE];
    > > char Event[64];
    > >
    > > TDaily* nxt_Daily;
    > >
    > > I have defined my constructor/copy methods as shown:
    > >
    > > TDaily* init_date(TDaily **pDaily);
    > > TDaily* Copy(const TDaily &copy); // Copy constructor
    > > void operator=(const TDaily &copy);
    > >
    > > I try to use my copy constructor in my program as below:
    > > TDaily bfr_date = tmp;
    > >
    > > I get the following error:
    > > Settings.cpp: In method `class TDaily * TDaily::Edit_date(TDaily **,
    > > TBike *)':
    > > Settings.cpp:698: conversion from `TDaily *' to non-scalar type `TDaily'
    > > requested
    > >
    > > I do not see where my fubar is... any ideas?

    >
    > Post real code. And make it complete and compilable this time.
    >
    > V


    You want me to post over 10K lines of code?

    Please...
    --
    #----------------------------------------------------------#
    # "Don't fear the penguin!" #
    #----------------------------------------------------------#
    # Registered Linux user: #309247 http://counter.li.org #
    #----------------------------------------------------------#
     
    Joe Cipale, May 21, 2004
    #4
  5. > I have defined my constructor/copy methods as shown:
    >
    > TDaily* init_date(TDaily **pDaily);
    > TDaily* Copy(const TDaily &copy); // Copy constructor
    > void operator=(const TDaily &copy);
    >


    I think you need to define the copy constructor. The signature
    for the constructor would be:

    TDaily::TDaily( const TDaily &copy)

    Sandeep
    --
    http://www.EventHelix.com/EventStudio
    EventStudio 2.0 - System Architecture Design CASE Tool
     
    EventHelix.com, May 21, 2004
    #5
  6. Joe,
    this line doens't look right, constructors don't return values !
    TDaily* Copy(const TDaily &copy); // Copy constructor
    and
    your assignment operator= doesn't look kosher as well,
    void operator=(const TDaily &copy);
    an assignment operator should return a reference:
    TDaily& operator=( const TDaily& copy)

    Also, the TDaily* stuff doens't seem good style, you should only
    involve TDaily's and TDaily references, why would you want to
    have a pointer, then you have to check it actually points to something!

    dave

    "Joe Cipale" <> wrote in message
    news:...
    > I have a class defined as follows:
    > public:
    > char Date[2 * BYTE];
    > char weight[6];
    > char Workout[2 * BYTE];
    > char Event[64];
    >
    > TDaily* nxt_Daily;
    >
    > I have defined my constructor/copy methods as shown:
    >
    > TDaily* init_date(TDaily **pDaily);
    > TDaily* Copy(const TDaily &copy); // Copy constructor
    > void operator=(const TDaily &copy);
    >
    > I try to use my copy constructor in my program as below:
    > TDaily bfr_date = tmp;
    >
    > I get the following error:
    > Settings.cpp: In method `class TDaily * TDaily::Edit_date(TDaily **,
    > TBike *)':
    > Settings.cpp:698: conversion from `TDaily *' to non-scalar type `TDaily'
    > requested
    >
    > I do not see where my fubar is... any ideas?
    >
    > Joe
    >
    > #----------------------------------------------------------#
    > # Penguinix Consulting #
    > #----------------------------------------------------------#
    > # Software development, QA and testing. #
    > # Linux support and training. #
    > # "Don't fear the penguin!" #
    > #----------------------------------------------------------#
    > # Registered Linux user: #309247 http://counter.li.org #
    > #----------------------------------------------------------#
     
    Dave Townsend, May 21, 2004
    #6
  7. "Joe Cipale" <> wrote...
    > Victor Bazarov wrote:
    > >
    > > Joe Cipale wrote:
    > > > I have a class defined as follows:
    > > > public:
    > > > char Date[2 * BYTE];
    > > > char weight[6];
    > > > char Workout[2 * BYTE];
    > > > char Event[64];
    > > >
    > > > TDaily* nxt_Daily;
    > > >
    > > > I have defined my constructor/copy methods as shown:
    > > >
    > > > TDaily* init_date(TDaily **pDaily);
    > > > TDaily* Copy(const TDaily &copy); // Copy constructor
    > > > void operator=(const TDaily &copy);
    > > >
    > > > I try to use my copy constructor in my program as below:
    > > > TDaily bfr_date = tmp;
    > > >
    > > > I get the following error:
    > > > Settings.cpp: In method `class TDaily * TDaily::Edit_date(TDaily **,
    > > > TBike *)':
    > > > Settings.cpp:698: conversion from `TDaily *' to non-scalar type

    `TDaily'
    > > > requested
    > > >
    > > > I do not see where my fubar is... any ideas?

    > >
    > > Post real code. And make it complete and compilable this time.
    > >
    > > V

    >
    > You want me to post over 10K lines of code?
    >
    > Please...


    No, I don't want you to post 10K lines of code. I want you to read
    the damn FAQ 5.8 and follow its recommendations.
     
    Victor Bazarov, May 21, 2004
    #7
  8. "Dave Townsend" <> wrote in message
    news:...
    >
    > Joe,
    > this line doens't look right, constructors don't return values !
    > TDaily* Copy(const TDaily &copy); // Copy constructor


    They aren't called Copy either!

    john
     
    John Harrison, May 21, 2004
    #8
  9. > > >
    > > > I do not see where my fubar is... any ideas?

    > >
    > > Post real code. And make it complete and compilable this time.
    > >
    > > V

    >
    > You want me to post over 10K lines of code?
    >


    You wrote 10K lines of code without realising you didn't have a copy
    constructor!! Ever heard of incremental development? Unit testing?

    john
     
    John Harrison, May 21, 2004
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jazz
    Replies:
    3
    Views:
    763
    Kristian Bisgaard Lassen
    Oct 28, 2003
  2. VisionSet
    Replies:
    8
    Views:
    4,901
    Tris Orendorff
    Apr 29, 2004
  3. Alex
    Replies:
    2
    Views:
    1,230
  4. Replies:
    26
    Views:
    2,117
    Roland Pibinger
    Sep 1, 2006
  5. Rahul
    Replies:
    2
    Views:
    761
Loading...

Share This Page