Hello,

This is my first post here, although I have been browsing these forums for a while now, and I must say this is quite an informative place.

I have a small question that I would like to post, more to verify if I am correct or not in how this should be implemented.

I am working in Visual Studio 2005, and using managed C++ code with /clr. I have a struct definition, wich needs to be returned from a function. Sample code would be as follows:

// This would be the struct definition, at the start of the project. 
// It's defined directly in the project namespace, not inside a class:

public ref struct TheStruct              
    {
        int structval1;
        int structval2;
    };

// This would be a function inside a class (which resides in the same 
// namespace as the struct) to return the struct.
// Inside the function, another similarily declared struct is used as 
// source to convert it into TheStruct.

TheStruct^ ConvertStruct(SomeOtherStruct s)
{
     TheStruct tmp;
     tmp.structval1 = s.someval1 / 255;
     tmp.structval2 = s.someval2 / 255;
     return ^tmp;
}

// finally, the conversion is called in source as:

TheStruct MyWorkStruct = ConvertStruct(MyOtherStruct);

Will this work?

Thank you already for any replies :)

Recommended Answers

All 2 Replies

Will this work?

Why don't you try and see?

Why don't you try and see?

I would, were it that I could atm. However, I am not having access to the VS compiler right now and writing my project some text editor. Since I'm using the mentioned setup in several places inside my project, I'd rather be correct from the start, than having to search through the whole code when I am able to compile late at night.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.