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

C1001 at msc1.cpp:2701 when specializing template member

VC 7.1.3088 Bug: When a class defines a template member function taking (T const &),
then an explicit specialization taking a non-const & argument (U) causes a C1001 at msc1.cpp line 2701.

The following short program duplicates this error.
Compile it in Debug mode (all optimizations disabled), with "Not using precompiled headers".

Class C defines F as a template member function taking (_T const &).
It then specializes F taking a char.
a) If the specialization signature is (char const &), it compiles OK.
b) If the specialization signature is (char) or (char &), it fails with a C1001.

VC6 and VC7.0 compile (b) without any problems.

Nov 16 '05 #1
9 2742
Eric Wang wrote:
VC 7.1.3088 Bug: When a class defines a template member function
taking (T const &),
then an explicit specialization taking a non-const & argument (U)
causes a C1001 at msc1.cpp line 2701.

The following short program duplicates this error.


Did you intend to include the short program?

-cd
Nov 16 '05 #2
> Did you intend to include the short program?

Very damn frustrating.
I've tried posting my program 8 times. The server gives an error every time.

I shorten my program from 10 lines to 8, to 6, to 5. Error, error, error.
I shortened it to 1 line. That worked.

Does the server accept only 1 line of C++ code per post?
Does it choke on curly brace, semicolon, or other C++ characters?
Nov 16 '05 #3
class C { public:

Nov 16 '05 #4
ALERT: CHANGE ALL [ to angleopen, ] to angleclose. (I had to do this to get the server to accept this post.)
---- begin foo.cpp ----
class C
{
public:
template[typename _T] void F(_T const &);
template[] void F(char
// Comment out the following line to generate a C1001 at msc1.cpp:2701.
const &
);
};

void main(void) { C c; c.F('a'); }
---- end foo.cpp ----

Nov 16 '05 #5
The server chokes on any code containing anglebracket open or close?
<>
Nov 16 '05 #6
Line 2: template angleopen typename T angleclose void F(T const &);

Nov 16 '05 #7
I could not post my C++ code containing angle brackets in standard template notation.
I kept getting:

Server Error in '/library' Application.
--------------------------------------------------------------------------------
Runtime Error
Description: An application error occurred on the server.

I had to replace the angle brackets with square brackets. That worked.
Nov 16 '05 #8
Eric Wang wrote:
Did you intend to include the short program?


Very damn frustrating.
I've tried posting my program 8 times. The server gives an error
every time.


I think it's a problem with posting through the web-based newsreader. If
you use an NNTP client (Outlook Express, Forte Agent, etc), then you can
post C++ source code with no problems.

-cd
Nov 16 '05 #9
Eric Wang wrote:
ALERT: CHANGE ALL [ to angleopen, ] to angleclose. (I had to do this
to get the server to accept this post.)
---- begin foo.cpp ----
class C
{
public:
template[typename _T] void F(_T const &);
template[] void F(char
// Comment out the following line to generate a C1001 at
msc1.cpp:2701. const &
);
};

void main(void) { C c; c.F('a'); }
---- end foo.cpp ----


I was able to reproduce your ICE. Unfortunately, this code is not valid
C++: According to the C++ standard, you're not allowed to explicitly
specialize a template member function inline in the class definition.

Move your specialization out of the class definition and it's both legal
C++, and VC7.1 will compile it:

class C
{
public:
template<typename _T> void F(_T const &);
};

template<> void C::F(char const &)
{
}

int main()
{
C c;
c.F('a');
}

-cd
Nov 16 '05 #10

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

Similar topics

2
by: Patrick McConnell | last post by:
The following code gives the link error: Unresolved external 'C1<int>::f()' referenced from D:\PROGRAM FILES\BORLAND\CBUILDER5\PROJECTS\MAIN.OBJ Using Borland CBuilder5. If i define the body...
0
by: Gianni Mariani | last post by:
I remember seeing a neat template specialization trick posted here a few months ago that allowed the detection of a type containing a member. After a day searching through google archives I come up...
2
by: Ruben Campos | last post by:
I have a problem with a template function that is declared as a friend of a template class. I'll first show the exact problem with source code: // MyClass.hpp template <typename T> class...
3
by: Lionel B | last post by:
Greetings. In a template class for which a template parameter may be another template class, I would like to be have access to the type of the nested template parameter. Hopefully the following...
2
by: Dominik Fritz | last post by:
Hi, I have a template class which contains a nested class. The .cpp file is included at the end of the header file. If I write the implementation of a member function of my nested class in this...
13
by: john.constantine | last post by:
Hi I have this code: template<typename ClassType> struct S { template<typename FunctionType> void member() {}; };
5
by: krema2ren | last post by:
Hi Does some of you know how to declare getCollection() in the cpp file? My code snippet below produces following compile error: foo.cpp(48) : error C2143: syntax error : missing ';' before...
14
by: aaragon | last post by:
Hi everyone, I've been writing some code and so far I have all the code written in the .h files in order to avoid the linker errors. I'm using templates. I wanted to move the implementations to...
3
by: Stefan Bollmann | last post by:
Hi, i wonder about a problem with functions i cannot put out of my main.cpp file into one *.h and *.cpp. When I run this little testprogram: #include <iostream> #include <vector>...
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: 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
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
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...
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,...

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.