M
Martin Zenkel
The follwing code compiles and works well under VS 2002
with or without the line "template A<int>". Using VS 2003
the code throws an exception if the line "template
A<int>" is removed.
From my point of view explicit instantiation of templates
should not be necessary and usually produces more code
than needed.
Is this a known bug of the c++ compiler?
#include <iostream>
#using <mscorlib.dll>
template <class C>
class A
{
public:
C c;
int i;
A(): i(0), c(C())
{
}
A(const A& a): i(a.i), c(a.c)
{
}
~A()
{
}
const A& operator=(const A& a)
{
if (this != &a)
{
c = a.c;
i = a.i;
}
return a;
}
};
//template A<int>;
public __gc class M
{
public:
M()
{
}
void compute(A<int> a)
{
std::cout << "M::compute(...): a.i: " <<
a.i;
}
void test()
{
A<int> a;
compute(a);
}
};
using namespace std;
int main()
{
cout << "Program active" << endl << endl;
M* m = new M();
m->test();
cout << endl << "Program terminated." << endl;
int c;
cin >> c;
return 0;
}
with or without the line "template A<int>". Using VS 2003
the code throws an exception if the line "template
A<int>" is removed.
From my point of view explicit instantiation of templates
should not be necessary and usually produces more code
than needed.
Is this a known bug of the c++ compiler?
#include <iostream>
#using <mscorlib.dll>
template <class C>
class A
{
public:
C c;
int i;
A(): i(0), c(C())
{
}
A(const A& a): i(a.i), c(a.c)
{
}
~A()
{
}
const A& operator=(const A& a)
{
if (this != &a)
{
c = a.c;
i = a.i;
}
return a;
}
};
//template A<int>;
public __gc class M
{
public:
M()
{
}
void compute(A<int> a)
{
std::cout << "M::compute(...): a.i: " <<
a.i;
}
void test()
{
A<int> a;
compute(a);
}
};
using namespace std;
int main()
{
cout << "Program active" << endl << endl;
M* m = new M();
m->test();
cout << endl << "Program terminated." << endl;
int c;
cin >> c;
return 0;
}