forward declarations and generic containers

O

omellet

I'm trying to define a class, A, that has a List<> of interface
instances, IA. IA has a property pointing back to a class A instance,
so I need to forward define IA in order to use it in A.

#include "stdafx.h"

using namespace System;
using namespace System::Collections::Generic;

interface class IA;

ref class A {
public:
List<IA^> coll_;
};

interface class IA {
public:
property IA^ myIA { IA^ get(); }
};

int main(array<System::String ^> ^args)
{
A^ a = gcnew A();
a->coll_ = gcnew List<IA^>();
return 0;
}

compiler output:

fwdTests.cpp
fwdTests.cpp(24) : error C2582: 'operator =' function is unavailable in
'System::Collections::Generic::List<T>'
with
[
T=IA ^
]

Is this a bug, or am I not supposed to be able to do this?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top