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.
Printable View
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.
The assignment operator is implicitely defined for C++ classes/structs. What is the compiler are you using, what error are you getting?
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.
post code?
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
}
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
}
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?
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