Struct question

This is a discussion on Struct question within the C++ Programming forums, part of the General Programming Boards category; Hey guys, I have created a struct and have 3 struct objects, I have tried to say for example object1 ...

  1. #1
    182
    182 is offline
    Registered User
    Join Date
    Oct 2005
    Posts
    133

    Struct question

    Hey guys,

    I have created a struct and have 3 struct objects, I have tried to say for example object1 = object2 but it doesn't seem to work so I was wondering how you do this:?

    Thanks.

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    The assignment operator is implicitely defined for C++ classes/structs. What is the compiler are you using, what error are you getting?

  3. #3
    182
    182 is offline
    Registered User
    Join Date
    Oct 2005
    Posts
    133
    I am using MSVC 6, if I pass the struct as a parameter I get the error that the struct is an undeclared identifer if I make it global I don't get an error and it doesn't work but it has been declared and the object1 struct has been initlised and has the values the other struct needs. So i thought object1=object2 would work.

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    post code?
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    182
    182 is offline
    Registered User
    Join Date
    Oct 2005
    Posts
    133
    I haven't got the full version of the code with me at the moment but its along the lines of the following:

    I have also tried passing the second struct by reference as well when I did that it compiled but just wouldn't store the info in the second object

    //global struct

    struct1 object 2;

    Code:
    void func ()
    
    {
    
    struct1 object1
    
    //calculations etc...
    
    func2( object1)
    
    }
    
    void func2(struct1 &object1)
    
    {
    
    object1 = object2;
    
    //calculations with object 2
    
    
    }

  6. #6
    182
    182 is offline
    Registered User
    Join Date
    Oct 2005
    Posts
    133
    I haven't got the full version of the code with me at the moment but its along the lines of the following:

    I have also tried passing the second struct by reference as well when I did that it compiled but just wouldn't store the info in the second object

    Code:
    //global struct 
    
    struct1 object 2;
    
    
    void func ()
    
    {
    
    struct1 object1
    
    //calculations etc...
    
    func2( object1)
    
    }
    
    void func2(struct1 &object1)
    
    {
    
    object1 = object2;
    
    //calculations with object 2
    
    
    }

  7. #7
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Hard totell unless we see the real code. object2 should have no spaces in the name, but I guess that's from not being the real code?
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  8. #8
    182
    182 is offline
    Registered User
    Join Date
    Oct 2005
    Posts
    133
    Thanks I was also wondering will the object2 struct have to have all its members initlised in another function before I can use the object1=object2 code? Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with linked list sorting function
    By Jaggid1x in forum C Programming
    Replies: 6
    Last Post: 06-02-2009, 02:14 AM
  2. Struct question... difference between passing to function...
    By Sparrowhawk in forum C++ Programming
    Replies: 6
    Last Post: 02-23-2009, 02:59 PM
  3. Looking for a way to store listbox data
    By Welder in forum C Programming
    Replies: 20
    Last Post: 11-01-2007, 11:48 PM
  4. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 03:49 PM
  5. towers of hanoi problem
    By aik_21 in forum C Programming
    Replies: 1
    Last Post: 10-02-2004, 01:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21