-1

I'm trying to programmatically create and track objects but have been unable to in a C++ CLI application. I've tried using vector and the CLI equivalent cliext, both of which threw errors. In a normal C++ application, I have had no problem creating a set of objects and retrieving data from them using std::vector<Player> player(8), with Player being the class, player being the reference, and (8) being the number of objects. To store data, or retrieve, I can then just run the method for that class player[4].SetColor(22);. It seems that CLI is expecting managed code, which cliext should handle, but I have run into errors when running it that way as well:

Severity Code Description   Project File Line Suppression State
Error   C4484   'cliext::impl::vector_select<_Value_t,true>
::default::get': matches base ref class method 
'cliext::impl::vector_impl<_Value_t,true>::default::get',
but is not marked 'virtual', 'new' or 'override'; 'new'
(and not 'virtual') is assumed

and:

Severity Code Description Project File  Line Suppression State
Error C3673 'Player': class does not have a copy-constructor    

Though like I said, runs fine without CLI.

Any help/examples for CLI would be appreciated, thanks!

Zeloz
  • 63
  • 7
  • Does `Player` have a copy constructor or support the Rule of Zero? Sounds to me like the compiler could be trying to warn you that you're [making a terrible mistake](https://stackoverflow.com/questions/4172722/what-is-the-rule-of-three). – user4581301 Feb 03 '19 at 04:01
  • It does not, though I thought it created a default one. I have tried to add one but am seeing another error while doing so: ```an ordinary reference to a C++/CLI ref class or interface class is not allowed ```. Was trying to follow this link: https://www.tutorialspoint.com/cplusplus/cpp_copy_constructor.htm – Zeloz Feb 03 '19 at 04:55
  • The default copy constructor is often useless when the object [owns](https://stackoverflow.com/questions/49024982/what-is-ownership-of-resources-or-pointers) manually controlled resources like dynamic memory allocations. I don't know my CLI well enough to help with the new error.. I recommend adding your code, preferably a [mcve]. The true beauty of the MCVE is when creating one you very often expose the bug and can solve the problem yourself. – user4581301 Feb 03 '19 at 06:38
  • Here is I believe the minimum project that results in the same error. I'm not even sure if/how CLI handles copy-constructors (still looking into it though): https://1drv.ms/u/s!Aj-jC988qcQojTNuY162Uwn5DZBo – Zeloz Feb 03 '19 at 19:01
  • The Internet is littered with computers broken or corrupted because their users clicked links that look like that. Put the code in the question as text please. – user4581301 Feb 03 '19 at 19:05
  • Couldn't add it all in comments, does wandbox work? https://wandbox.org/permlink/uFDrfKqV0N2atVwS . Also, I didn't see anywhere to make a CLI version in wandbox so it would have to be redone within Visual Studio. – Zeloz Feb 03 '19 at 19:28
  • At the bottom of the question there'll be an edit link. Use that. – user4581301 Feb 03 '19 at 19:42
  • I looked at the wandbox link. You'll also need to provide code for `Player` and probably `cliext::vector` for anyone to have enough information to help. – user4581301 Feb 03 '19 at 19:49
  • Here's the page that talks about cliext::vector https://learn.microsoft.com/en-us/cpp/dotnet/vector-stl-clr?view=vs-2017 . Though, I would use another class/library if it was able to create a list of player objects. Oh, does wandbox not show the 3 header files? I'll put all the files in one page (working C++ and non working CLI, each with the main and class files): https://wandbox.org/permlink/6VfolfOmLrqaU8Pp – Zeloz Feb 03 '19 at 20:25

1 Answers1

1

I was able to create a list of objects within C++ CLI using array< Player^ >^ player = gcnew array< Player^ >(playerCount);. After which, I could then just create new players for all the objects I needed player[(the number of the player)] = gcnew Player;. Reference: https://learn.microsoft.com/en-us/cpp/dotnet/how-to-use-arrays-in-cpp-cli?view=vs-2017

Zeloz
  • 63
  • 7