473,396 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

forward declarations and generic containers

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?

Jan 13 '06 #1
2 1297
List<IA^> coll_;

Try changing that to

List<IA^>^ coll_;

--
Regards,
Nish [VC++ MVP]
<om*****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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?

Jan 13 '06 #2
Duh. Thanks!

Jan 17 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: mjm | last post by:
Folks, Please help me with the following problems: ******************************************** 1. I have a class template template<class Base> class Matrix : public Base { /* .... */ }
6
by: Steven T. Hatton | last post by:
Should I be able to forward declare something from a namespace different from the current one? For example the following code compiles: //testdriver.hpp #ifndef TESTDRIVER_HPP #define...
2
by: Marcin Kalicinski | last post by:
Hi All, In some headers meant to work with both C and C++ the following is often found: typedef struct tagMyStruct { /*some members*/ } MyStruct; Can I forward-declare MyStruct somehow? ...
5
by: Simon Elliott | last post by:
For some time I've been using typedefs for STL containers for reasons outlined in: http://www.gotw.ca/gotw/046.htm However a major downside to this is that you can't forward declare a typedef...
11
by: aleko | last post by:
This applies equally to function prototypes. Why do we have to tell the compiler twice? Other modern compiled languages don't have this requirement. Just curious, Aleko
7
by: Noah Roberts | last post by:
I have something like the following: template<ENUM X, int I = 0> class Generic { .... }; typedef Generic<Val1> v1_type; typedef Generic<Val2> v2_type;
3
by: NickC | last post by:
I am using .NET version 2.0 and implementing all my event handlers to use the new generic type. The problem I am running into is most of my Event Arguments are defined in a single header which...
6
by: Hunk | last post by:
Hi I have a question on usage of forward declarations of templates. While searching through this group , people suggested using forward declarations and typedefs for templates as // in...
11
by: Jef Driesen | last post by:
I have the following problem in a C project (but that also needs to compile with a C++ compiler). I'm using a virtual function table, that looks like this in the header file: typedef struct...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.