-
copy struct to class
Can anyone tell me how I can copy the contents of a struct into a class so that the class's member functions can access the data contained within the struct?
I need to be able to access a struct with the member functions of a seperate class... and I do not know how to do this.
-
Can't you just pass the struct as a pointer to a member function?
Eg:
Code:
class someclass
{
public:
readstruct(somestruct * astruct);
};
readstruct(somestruct * astruct)
{
return astruct->somedata;
}
-
Ya I assumed a pointer was involved, however i do not know how to do this... (im very very new to this)...
I mean what is the :
Code:
return astruct->somedata;
arrow for?
and I need to be able to copy the data from the struct into something that the class can access...
Not to mention I get errors:
:22: `mystruct' was not declared in this scope
22: `b_struct' was not declared in this scope
22: invalid data member initialization
22: (use `=' to initialize static data members)
22: ISO C++ forbids declaration of `readstruct' with no type
When I add this to my class.h file:
public:
readstruct(mystruct * b_struct);
-
I was just giving an example, there is no "somestuct" struct...or any value named "somedata" for that matter...
Code:
return astruct->somedata;
the "->" operator is basically the same as:
Code:
return (*astruct).somedata;
(or something like that, just use -> instead of . when working with ptrs)
I would suggest finding a good pointer tutorial and reading up on them...I'll post one if i have time, but its getting late and I have homework to do :D