Answered by:
Cannot use Platform::Collections::Vector in WinRT method signature

Question
-
When I try to make a public method with a WinRT Vector, I get an error:
void setVector(Platform::Collections::Vector<Platform::String^>^);
error C3986: 'setVector': signature of member contains native type 'std::equal_to<_Ty>'
I can write my own template class which uses a Vector on the inside.
template <typename T> public ref class MyTemplateClass sealed { public: MyTemplateClass(void){myVector = ref new Platform::Collections::Vector<T>();} ~MyTemplateClass(void){} T GetAt(unsigned int i){return myVector->GetAt(i);} void SetAt(unsigned int index, T item){myVector->SetAt(index, item);} void Append(T item){myVector->Append(item);} private: Platform::Collections::Vector<T>^ myVector; };
then use
void setVector(MyTemplateClass<Platform::String^>^);
But this seems rather silly, no?
One more observation. This:
template <typename X> public ref class MyOtherClass sealed { public: MyOtherClass(void){} ~MyOtherClass(void){} void setVector(Platform::Collections::Vector<Platform::String^>^ vector); };
compiles. This:
public ref class MyOtherClass sealed { public: MyOtherClass(void){} ~MyOtherClass(void){} void setVector(Platform::Collections::Vector<Platform::String^>^ vector); };
gives the same C3986 error. What's the real difference? Both seem like a valid use.
- Edited by Brian Alexander1 Thursday, March 29, 2012 1:19 AM
Thursday, March 29, 2012 12:48 AM
Answers
-
Ah I think I found the answer.
Use Windows::Foundation::Collections::IVector when passing the reference.
http://msdn.microsoft.com/en-us/library/windows/apps/hh441569(v=vs.110).aspx (See "Collections and Arrays")
- Marked as answer by Brian Alexander1 Thursday, March 29, 2012 2:08 AM
Thursday, March 29, 2012 2:08 AM
All replies
-
Ah I think I found the answer.
Use Windows::Foundation::Collections::IVector when passing the reference.
http://msdn.microsoft.com/en-us/library/windows/apps/hh441569(v=vs.110).aspx (See "Collections and Arrays")
- Marked as answer by Brian Alexander1 Thursday, March 29, 2012 2:08 AM
Thursday, March 29, 2012 2:08 AM -
Thanks for sharing the solution.
Best regards,
JesseJesse Jiang [MSFT]
MSDN Community Support | Feedback to us
Thursday, March 29, 2012 11:09 AM -
This is the reason. Fixed my problem.
Wednesday, September 19, 2012 5:46 PM