473,804 Members | 3,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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::Collect ions::Generic;

interface class IA;

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

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

int main(array<Syst em::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::Collec tions::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 1319
List<IA^> coll_;

Try changing that to

List<IA^>^ coll_;

--
Regards,
Nish [VC++ MVP]
<om*****@gmail. com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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::Collect ions::Generic;

interface class IA;

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

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

int main(array<Syst em::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::Collec tions::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
5469
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
5221
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 TESTDRIVER_HPP #include <ostream> namespace ns_testdriver{ using std::ostream;
2
2821
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? Or more generally, can I forward declare a typedef or an enum? Also, is
5
10373
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 of a STL container: #include <vector> struct foo
11
2453
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
6001
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
1347
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 requires me to place some forward declarations in sorce files that reference these classes. The new generic EventHandler<T> requires that T is of a type EventArgs. My question is how do I create a forward declaration that includes the base class? ...
6
8622
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 myfile.h template<typename T,typename R> class some_class;
11
8340
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 device_t { const device_backend_t *backend; ... } device_t; typedef struct device_backend_t {
0
9708
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10589
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10327
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7625
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3828
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2999
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.