Click to See Complete Forum and Search --> : vectors
dave2k
December 18th, 2005, 07:19 AM
i am having trouble wth vectors
when i try vector<PokerGame> games;
i get this: c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\vector(506): error C3149: 'PokerGame' : illegal use of managed type 'PokerGame'; did you forget a '*'?
but when i try vector<PokerGame*>* games;it works fine. The latter was just a hack. Could someone explain why this works?
cheers.
NoHero
December 18th, 2005, 07:42 AM
Because in Managed C++ any non-value type is a reference to the object on the managed heap. Such a reference is expressed with the pointer asterisk. Any managed object which lies on the managed heap and is a non-value type, must be explicity allocated using __gc new and/or gcnew in the new syntax.
Btw do not use old non-managed std::vector along with new managed types. Use the languange constructs instead as described in 4.5 __gc arrays (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmxspec/html/vcManagedExtensionsSpec_4_5.asp) for old syntax and the array keyword for the new one as described here (http://nohero.blogsome.com/2005/11/08/the-new-managed-c-syntax/).
dave2k
December 18th, 2005, 08:33 AM
ok cheers
one more question:
normally if you wanted to pass a struct to a fucntion, the function would take maybe a constant reference - how would you do this in mc++? considering it has to be a pointer..
is the following the correct way?:
__gc struct Line {
bool dealerLine;
String *player;
};
void PartyPokerTable::ProcessLine(Line *line)
cheers
NoHero
December 18th, 2005, 10:39 AM
Yes. Remember __gc struct is not a value type, rather than a managed class where each member is public for default. That's why you need the pointer asterisk here.
codeguru.com
Copyright WebMediaBrands Inc., All Rights Reserved.