locked
How to create a vector of a value class?

    Question

  • I've created a little debug console widget for my windows store app, and I want to be able to log stuff to it before its template is applied, so I am attempting to create a vector of entries logged to it and then dump them into the widget when the template is applied. All the code-behind works fine when I store them as one long string, but that's not quite sophisticated enough, so I want a vector of entries. I can't seem to get the type signature and visibility of the associated classes correct though. This is as few errors as I've gotten, and the error I'm currently getting is

    Error 11 error C2440: 'return' : cannot convert from 'Thing::Consolel::PreinitEntry' to 'Platform::Object ^' C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\collection.h 801 1 Thing

    	public enum class CSym {
    		END,
    		LF,
    		INFO,
    		ERR,
    		INVALID
    	};
    	public ref class Consolel sealed : public Windows::UI::Xaml::Controls::Control
    	{
    	public:
    		Consolel();
    		void OnApplyTemplate() override;
    		void RegisterDependencyProperties();
    	internal:
    		Consolel^ operator << (Platform::String^ str);
    		Consolel^ operator << (Platform::Object^ obj);
    		Consolel^ operator << (CSym sym);
    		Consolel^ operator << (DWORD hr);
    		Consolel^ operator << (double d);
    		Consolel^ operator << (int i);
    		Consolel^ operator << (unsigned int i);
    		Consolel^ operator << (UINT64 i);
    		static enum class PreinitEntryType {
    			SYM,
    			STRING
    		};
    	private:
    		Windows::UI::Xaml::Controls::ScrollViewer^			m_scroller;
    		Windows::UI::Xaml::Controls::TextBlock^				m_textBlock;
    		Windows::UI::Core::CoreDispatcher^					m_coreDispatcher;
    		void												AsyncAppend(Platform::String^ str);
    		void												AsyncAppend(CSym sym);
    		value class PreinitEntry {
    		public:
    			PreinitEntryType	typ;
    			Platform::String^	str;
    			Thing::CSym				sym;
    		};
    		Platform::Collections::Vector<PreinitEntry>^		m_preinit;
    	};

    I then try to insert things into the vector like this (which the compiler seems okay with, but I'm still not sure it's correct):

    PreinitEntry ent = { PreinitEntryType::SYM, nullptr, sym};
    m_preinit->Append(ent);
    

    Sunday, September 07, 2014 12:40 AM

Answers

  • Hi Magus,

    Hardly to tell why but it seems that the error occurs at your m_preinit->Append(ent) line, am I correct?

    I guess it might because Platform::Collections::Vector Class does not allow value class as its type, the allowed types are: integers, interface class ^, public ref class^, value struct, public enum class. For more information plz ref to : Value classes and structs

    Also could you also initialize your m_preinit array?

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.



    Monday, September 08, 2014 6:37 AM
    Moderator