473,385 Members | 1,536 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,385 software developers and data experts.

Templated Copy Ctor

Hi,

I have a query regarding VC6 and its handling of templated copy
constructors. Here goes:

Take a look at the following code sample...
template<class _Ty, size_t t_uiSize = 10 >
class my_template
{
public:

my_template()
{
printf("construct\r\n");
}

my_template( const my_template<_Ty,t_uiSize> &mt)
{
printf("construct by copying\r\n");
}

template<class _Other>
my_template(const my_template<_Other, t_uiSize> &mt )
{
printf("construct from a related class\r\n");
}
};


class myclass
{

};

class myotherclass
{

};


int main(int argc, char* argv[])
{
my_template<myclass> var1; // ctor
my_template<myclass> var2 = var1; // copy ctor
my_template<myotherclass> var3 = var1; // ctor from related

return 0;
}
The non-templated copy ctor must be defined BEFORE the templated copy
ctor so that it would build without error. If you define them the
wrong way around, you get:

fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'msc1.cpp', line 1794)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more
information

....however, if you define them with the non-templated copy ctor BEFORE
the templated copy ctor you get:

error C2535: '__thiscall
my_template<_Other,`template-parameter258'>::my_template<_Other,`template-parameter258'>(const
class my_template<_Other,`template-parameter258'> &)' : member
function already defined or declared

The compiler can't decern any difference between the two function
signatures. Weird. This works fine on VC7.

Now, if we add a "dummy" variable in the templated ctor's parameter
list, then everything compiles and works fine. eg:

template<class _Other>
my_template(const my_template<_Other, t_uiSize> &mt, int dummy = 1 )
{
printf("construct from a related class\r\n");
}

I'm looking for a reason for this, but suspect that it's due to poor
template handling by the vc6 compiler...again. It's important to note
that if the second tamplate parameter is removed (the default UINT
param) then everything works fine. Does anyone know what's going on
here?

Thanks,
Rich
Jul 22 '05 #1
1 1842
Rich wrote in news:32*************************@posting.google.co m:

[snip (template code)]

When the compiler screams:

fatal error C1001: INTERNAL COMPILER ERROR
[snip]
I'm looking for a reason for this,
Its reasonable to assume:

but suspect that it's due to poor
template handling by the vc6 compiler...again.
[snip]
Does anyone know what's going on
here?


Yes you do. Note VC6 is (in computer years) a very old compiler,
be thankfull you've found a workaround.

If possible upgrade to VC 7.1, its highly conformant, and you can put
all this nonsence behind you.

Note VC 7.0 was (and is maybe) little better than VC6 (some bugs removed,
some added) 7.1 is a major improvement.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #2

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

Similar topics

3
by: tirath | last post by:
Hi all, I have a templated class that derives from a non-templated abstract class. How do I then cast a base class pointer to a <templated> derived class pointer in a generalised fashion? ...
11
by: Sam Wilson [Bentley] | last post by:
If you pass a C++ object by value as an argument to a function which has a variable-length argument list (...), the MSVC7 C++ compiler does not call the object's copy constructor and will not...
2
by: ferdinand.stefanus | last post by:
Hi, I have some questions regarding templated class constructor: #include <iostream> using namespace std; template<typename T> class Foo { public:
5
by: kalita | last post by:
template<class T> class A { template<class Y> A(const A<Y> &) { // whatever } };
12
by: Robert.Holic | last post by:
Hi All (first time caller, long time listener), I've stumbled across a problem that I have yet to figure out, although Im sure I'll kick myself when I figure it out. Here it is: I need to...
6
by: Richard Thompson | last post by:
Hi - I have a program which was previously working (but wasn't well tested). I've added a new function call, and it now doesn't compile. The call requires a copy constructor, but the compiler...
2
by: subramanian100in | last post by:
If we do not provide any ctor for a class, the compiler provides the default ctor and copy ctor if needed. Consider a class Test. Suppose we provide some ctor in class Test but do not provide...
11
by: Dijkstra | last post by:
Hi folks! First, this is the code I'm using to expose the problem: ------------------------------------------------------------------ #include <functional> #include <string> #include...
5
Banfa
by: Banfa | last post by:
So I have a little problem, I have a template class and that class contains a template function; now what I want to do is declare that function in the class (or indeed the entire class) as a friend...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.