How to - Forward declaration in Visual C++ WinRT component?


  • I have 2 classes that need to know about each other: MessageManager, and Subscription.  I tried doing a forward declaration as I did in native C++, but I am getting an error message.

    MessageManager.h code:

    #pragma once
    #include "Object.h"
    #include <collection.h>
    namespace Gaia
    	// Forward declarations
    	ref class Subscription;
    	public ref class MessageManager sealed :
    		public Object
    		static property MessageManager^ Instance
    			MessageManager^ get() { return mInstance; }
    		virtual ~MessageManager();
    		virtual Platform::String^ GetType();
    		static MessageManager^ mInstance;
    		Platform::Collections::Map<Gaia::Subscription^, int>^ mSubscriptions;

    Subscription.h code:

    #pragma once
    #include "MessageHandler.h"
    #include "MessageManager.h"
    #include "Object.h"
    namespace Gaia

    Error message:

    Error 1 error C2678: binary '<' : no operator found which takes a left-hand operand of type 'Gaia::Subscription ^const ' (or there is no acceptable conversion) (MessageManager.cpp) c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstddef 180 1 Gaia

    Land Of Simeria - http://www.stormsonggames.com/los

    • Moved by Jesse Jiang Tuesday, October 16, 2012 2:58 AM (From:Visual C++ General)
    Monday, October 15, 2012 10:50 PM

All replies

  • Hi,

    Would you please provide us more codes about this issue?

    I try to reproduce your issue, cope the codes into my project and achieve Subscription class in Subscription.h. It builds well.

    I think this issue may caused by other codes.

    By the way, I will move this thread to Building Metro style apps with C++ forum. This forum only talk about native codes.

    Best regards,

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

    Tuesday, October 16, 2012 2:59 AM