Answered by:
VC++ 2010 exp. error C3225: generic type argument for 'T' cannot be '...

Question
-
My code of structures is:
struct Item { //map reader int id; int count; }; struct Container { int bp_id; System::Collections::Generic::List<Item> items = gcnew System::Collections::Generic::List<Item>; };
and error:
error C3225: generic type argument for 'T' cannot be 'Project::Item', it must be a value type or a handle to a reference type
What's wrong?
- Moved by Damon Zheng Monday, October 1, 2012 5:12 AM (From:Visual C++ Express Edition)
Thursday, September 27, 2012 3:34 PM
Answers
-
Note that you are mixing C++/CLI code with C++ code. In particular, you are adding a managed member variable to an unmanaged struct.
Most newcomers to Visual C++ may not appreciate that C++/CLI is a language separate and distinct from C++ that is used to support .NET concepts. What is particularly confusing is that both C++ and C++/CLI code can be intermixed in the same source file. Just because this is possible, doesn't mean it is desirable. If you are just learning C++, for example, I strongly urge you to stick with just C++ code (also called unmanaged code) until you gain further experience and confidence with the language. Once you are comfortable with C++ you can then take on C++/CLI later. As a general rule, C++/CLI is typically used to bridge .NET client applications with unmanaged DLL's.
In the case of your example, instead of using System::Collections::Generic::List<>, use std::vector<> instead.
- Edited by Brian Muth Thursday, September 27, 2012 9:06 PM
- Marked as answer by Dubler Sunday, September 30, 2012 8:40 PM
Thursday, September 27, 2012 9:06 PM
All replies
-
You need to define this as a handle to an Item:
System::Collections::Generic::List<Item^>^ items = gcnew System::Collections::Generic::List<Item^>();
When working with ref class types, you always work with a managed handle (^).
Reed Copsey, Jr. - http://reedcopsey.com
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".- Proposed as answer by Damon Zheng Monday, October 1, 2012 5:11 AM
Thursday, September 27, 2012 4:39 PM -
Note that you are mixing C++/CLI code with C++ code. In particular, you are adding a managed member variable to an unmanaged struct.
Most newcomers to Visual C++ may not appreciate that C++/CLI is a language separate and distinct from C++ that is used to support .NET concepts. What is particularly confusing is that both C++ and C++/CLI code can be intermixed in the same source file. Just because this is possible, doesn't mean it is desirable. If you are just learning C++, for example, I strongly urge you to stick with just C++ code (also called unmanaged code) until you gain further experience and confidence with the language. Once you are comfortable with C++ you can then take on C++/CLI later. As a general rule, C++/CLI is typically used to bridge .NET client applications with unmanaged DLL's.
In the case of your example, instead of using System::Collections::Generic::List<>, use std::vector<> instead.
- Edited by Brian Muth Thursday, September 27, 2012 9:06 PM
- Marked as answer by Dubler Sunday, September 30, 2012 8:40 PM
Thursday, September 27, 2012 9:06 PM -
error C3699: '^' : cannot use this indirection on type 'Project::Item'
error C3225: generic type argument for 'T' cannot be 'Project::Item *', it must be a value type or a handle to a reference typeFriday, September 28, 2012 10:08 PM -
List<T> is a C++/CLI type, which means you can only store "ref struct" or "ref class" types (C++/CLI types) within it. As Brian said, if you're trying to use all native code, you should avoid C++/CLI and don't compile with /clr. In that case, you can use std::vector to store these items.
Reed Copsey, Jr. - http://reedcopsey.com
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".Friday, September 28, 2012 10:42 PM -
Hello Dubler,
Visual C++ Express Edition Forum is for question about getting started with VC++ Express.
I moved your thread to Visual C++ Language Forum for better support.
Thanks for your understanding.
Regards,
Damon Zheng [MSFT]
MSDN Community Support | Feedback to us
Monday, October 1, 2012 5:48 AM -
correct answerWednesday, August 22, 2018 5:51 AM