Syntax for Overriding IListSource -Managed C++  
Author Message
A.Russell





PostPosted: Visual C++ Language, Syntax for Overriding IListSource -Managed C++ Top

I am having trouble with the syntax for overriding IList source in managed c++. Especially, how do you override the

public ref class StopListSource : Component, IListSource
{

private:
static BindingList<String^>^ blah = gcnew BindingList<String^>();


public:
StopListSource()
{}

StopListSource(IContainer^ container)
{
container->Add(this);
}

//***The Following generates: a member using-declaration or access declaration is illegal within a managed type
IListSource::ContainsListCollection
{
get { return false; }
}

//Not sure about the following, but it doesn't throw any errors

//in C# this is: System.Collections.IList IListSource.GetList() , but in C++ this is old syntax

static System::Collections::IList^ GetList = IListSource::GetList()
{


return blah;
}

};



Visual C++6  
 
 
Mike Danes





PostPosted: Visual C++ Language, Syntax for Overriding IListSource -Managed C++ Top

It's not old syntax, but you need to change static to virtual to compile that:

ref class ListSource : IListSource

{

static BindingList<String ^> ^list = gcnew BindingList<String ^>();

public:

property bool ContainsListCollection

{

virtual bool get() = IListSource::ContainsListCollection::get

{

return true;

}

}

virtual IList^ GetList() = IListSource::GetList

{

return gcnew ArrayList();

}

};


 
 
A.Russell





PostPosted: Visual C++ Language, Syntax for Overriding IListSource -Managed C++ Top

Thank you.

Just wondering, why did you return a new ArrayList() Shouldn't I return the BindingList object


 
 
Mike Danes





PostPosted: Visual C++ Language, Syntax for Overriding IListSource -Managed C++ Top

Ah, sorry... initially I did not have any BindingList in my sample but then I added to better match your sample and forgot to change GetList method.


 
 
A.Russell





PostPosted: Visual C++ Language, Syntax for Overriding IListSource -Managed C++ Top

Is it better if I return gcnew BindingList<T>^()
 
 
Mike Danes





PostPosted: Visual C++ Language, Syntax for Overriding IListSource -Managed C++ Top

That really depends on what you want to do with this list but probably not. What's the point in returning a new empty list every time (besides for me to do a confusing example )
 
 
A.Russell





PostPosted: Visual C++ Language, Syntax for Overriding IListSource -Managed C++ Top

Phew, I was having a hard time trying to work out what you were doing, but was sure it must be better than mine.

Thanks for you help, I spent hours reading MSDN about this today.