Question about structs in managed C++

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2006
Posts: 3
Reputation: shadevar is an unknown quantity at this point 
Solved Threads: 0
shadevar shadevar is offline Offline
Newbie Poster

Question about structs in managed C++

 
0
  #1
Aug 2nd, 2006
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:

  1. // This would be the struct definition, at the start of the project.
  2. // It's defined directly in the project namespace, not inside a class:
  3.  
  4. public ref struct TheStruct
  5. {
  6. int structval1;
  7. int structval2;
  8. };
  9.  
  10. // This would be a function inside a class (which resides in the same
  11. // namespace as the struct) to return the struct.
  12. // Inside the function, another similarily declared struct is used as
  13. // source to convert it into TheStruct.
  14.  
  15. TheStruct^ ConvertStruct(SomeOtherStruct s)
  16. {
  17. TheStruct tmp;
  18. tmp.structval1 = s.someval1 / 255;
  19. tmp.structval2 = s.someval2 / 255;
  20. return ^tmp;
  21. }
  22.  
  23. // finally, the conversion is called in source as:
  24.  
  25. TheStruct MyWorkStruct = ConvertStruct(MyOtherStruct);
Will this work?

Thank you already for any replies
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: Question about structs in managed C++

 
0
  #2
Aug 2nd, 2006
Originally Posted by shadevar
Will this work?
Why don't you try and see?
Last edited by WolfPack; Aug 2nd, 2006 at 7:29 am.
バルサミコ酢やっぱいらへんで
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 3
Reputation: shadevar is an unknown quantity at this point 
Solved Threads: 0
shadevar shadevar is offline Offline
Newbie Poster

Re: Question about structs in managed C++

 
0
  #3
Aug 2nd, 2006
Originally Posted by WolfPack
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC