locked
Platform::Collections::Map problem

    Question

  • Hi,

    I am trying to use a Map in my code.

    //something.h
    
    #pragma once
    #include <collection.h>
    #include "BasicComparer.h"
    //...
    
    typedef Platform::Collections::Map <Platform::String^, Platform::Object^> GamePageStartupArgs;
    
    public interface class something
    {
        //...
        void Initialize(GamePageStartupArgs^);
    }

    But when I try to compile this, I get 5 errors (all the same): 'Initialize': signature of member contains native type 'std::less<_Ty>'

    I also tried to use a custom managed comparer function: <Platform::String^, Platform::Object^, BasicComparer<Platform::String^>> ("BasicComparer.h"):

    template<class T> public ref class BasicComparer sealed{
    public:
    	bool operator() ( const T a, const T b) const{
    		return a < b;
    	}
    };

    But then I get other errors: "Error creating or communicating with child process." and "An internal error has occured in the compiler. xmemory0, line 628" 5 times.

    Is it my fault or is it a compiler bug?

    Any help would be appreciated.

    Sunday, March 25, 2012 2:48 PM

Answers

  • Hello,

    For the first question. You can use IMap instead of Platform::Collections::Map. Please follow these codes and this document.

    using namespace Platform;
    using namespace Windows::Foundation::Collections;
    
    typedef IMap <Platform::String^, Platform::Object^> GamePageStartupArgs;
    
    public interface class something
    {
        //...
        void Initialize(GamePageStartupArgs^ test);
    };
    

    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh755792(v=vs.110).aspx

    For the second question. Would you please show us the whole comparer function? I would suggest you to use lambda express instead of overwrite operator.

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Enarax Monday, March 26, 2012 6:49 PM
    Monday, March 26, 2012 6:07 AM

All replies

  • I was able to get some more informative error messages:

    "error C3072: operator '&' cannot be applied to an instance of a ref class" and
    "error C3073: 'Platform::Collections::Map<K,V>' : ref class does not have a user-defined copy constructor"

    And the problematic line is:

    property Platform::Collections::Map<Platform::String^, GameFramework::IDrawable^> mObjects;

    (in an interface)

    property Platform::Collections::Map<int, int> mObjects;

    Gives the same result.

    property Platform::Collections::Map<int, int>^ mObjects;
    Brings back the Internal Compiler Errors.

    • Edited by Enarax Sunday, March 25, 2012 6:47 PM
    Sunday, March 25, 2012 6:43 PM
  • Hello, Enarax.

    Try like this.

    --in yer class--

    public:

        property Platform::Object^ Objects

        {

            Platform::Object^ get()

           {

                return mObjects_;

           }

           void set(Platform::Object^ objects)

           {

                mObjects_ = dynamic_cast<Platform::Collections::Map<Platform::String^, GameFramework::IDrawable^>^>(objects);

           }

        }

    private:

        Platform::Collections::Map<Platform::String^, GameFramework::IDrawable^>^ mObjects_;

    ------------------

    Good luck!

    Monday, March 26, 2012 5:48 AM
  • Hello,

    For the first question. You can use IMap instead of Platform::Collections::Map. Please follow these codes and this document.

    using namespace Platform;
    using namespace Windows::Foundation::Collections;
    
    typedef IMap <Platform::String^, Platform::Object^> GamePageStartupArgs;
    
    public interface class something
    {
        //...
        void Initialize(GamePageStartupArgs^ test);
    };
    

    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh755792(v=vs.110).aspx

    For the second question. Would you please show us the whole comparer function? I would suggest you to use lambda express instead of overwrite operator.

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Enarax Monday, March 26, 2012 6:49 PM
    Monday, March 26, 2012 6:07 AM
  • Thanks a lot, it solved my problem. By the way I think they should improve the error messages, because it is hard to find out where the problem is.

    For the second question that is the whole code up there, it was basically just my attempt to reinterpret the std::less function with a ref class. Don't care about it.

    Thanks again
    Enarax

    Monday, March 26, 2012 7:24 PM