473,793 Members | 2,810 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing template instances by value to a managed function - Compiler Bug in VS 2003?

The following code works perfect in VS 2002 (compiled in a console
project). Using VS 2003 the variable 'a' in the 'compute' function of
the managed class 'M' is not correctly passed into this function.

Actually using the debugger shows that the copy constructor of class
'A' is called correctly, but nevertheless the variable 'a' in the
'compute' function is not initilized, that is 'a.i' has random values.

Additionally starting the application gives an exception after the
call of the 'compute' function.

I found that forcing the compiler to generate the template instance
'A<int>' using the code line
'template A<int>' solves the problem.

From my point of view this is a compiler bug!

Here is the code:

#include <iostream>
#using <mscorlib.dll >

template <class C>
class A
{
public:

C c;
int i;

A(): c(C()), i(0)
{
}

A(const A& a): c(a.c), i(a.i)
{
}
};

// Remove the comment signs in order to solve the problem
//template A<int>;

public __gc class M
{
public:

M()
{

}

void compute(A<int> a)
{
std::cout << a.i;
}
void test()
{
A<int> a;

compute(a);
}
};

int main()
{
M* m = new M();

m->test();

return 0;
}
Nov 16 '05 #1
0 973

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

Similar topics

17
6868
by: Paul MG | last post by:
Hi Template partial specialization always seems like a fairly straightforward concept - until I try to do it :). I am trying to implement the input sequence type (from Stroustrup section 18.3.1, 'Iseq'). I want the version for containers that he gives, but also to provide a specialization for construction from a pair<It,It> (eg because that is returned by equal_range()).
58
10183
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of code... TCHAR myArray; DoStuff(myArray);
4
6399
by: Gert Van den Eynde | last post by:
Hi all, A beginners question.... I've got a template class template <class T> classA {...} In an other class, I want to pass a pointer to an instance of classA as a function argument. How do I do this? Also, I want to have a data member for
13
2828
by: Walt Karas | last post by:
The following gives an error in the declaration of the member function x() of the class template Tpl, compiliing with a recent version of GCC under Solaris: class A { }; class B { }; template <typename Base> class Tpl : protected Base {
5
5306
by: nifsmith | last post by:
Hi I am trying to learn about Queues and use templates at the same time. I have written the following code and I am getting a link error, stating "unresolved external symbol, "int__cdecl adsq::QInitialise<struct adsq::Data>(struct adsq::Head<struct adsq::Data> *)" -----------adsq.h file
5
1971
by: Active8 | last post by:
vector<double> signal; vector<double>::iterator iter; in_file.load_vector(signal); in_file.load_vector(signal.begin()); those calls give the compiler error: "could not deduce template argument for 'T'" the infile object is a non-template class with a template function
5
1336
by: Hendrik Schober | last post by:
Hi, I had originally suspected this to be a bug in the std lib, that's why I started a thred in the STL newsgroup. However, it seems as if it is a compiler bug, so I'm transfering it to here. The original code was this: ----- Original Message -----
7
1665
by: cortfr | last post by:
If I compile the following code in my managed c++ dll... public ref class foo { public: void doSomething() { } }; public ref class bar { }; and then inspect the resulting dll using ildasm... I can see that foo
23
2157
by: osama178 | last post by:
Let's say I have this code -------------------- class GenericQueue { public: bool Pop(void*& refToPtr); // //--------------------(1) };
0
9518
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10433
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...
0
10000
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
7538
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
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4112
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2919
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.