I found the following compiler error with Microsoft Visual C++ .NET.
I use different functions with return types determined by a Traits class.
Function g() below works ok, but when I put the two declarations f1() and
f2(), the compiler gets disturbed. The error message does not even reproduce
the original code correctly. When the two declarations are switched, the
problem goes away.
Benedikt
//----------------------------------------
#include "stdafx.h"
template<class S,class T> struct Traits;
template<>
struct Traits<double,d ouble>
{
typedef double RType;
};
template<class T> class Matrix
{
public: typedef T Type;
};
template<class U, class V>
Matrix<typename Traits<typename U::Type,typenam e V::Type>::RType >
f1(const U& mat1, const V& mat2);
template<class U, class V>
Matrix<typename Traits<typename U::Type,V>::RTy pe>
f2(const U& mat1, const Matrix<V>& mat2);
template<class U, class V>
Matrix<typename Traits<typename U::Type,typenam e V::Type>::RType >
g(const U& mat1, const V& mat2)
{
return Matrix<U::Type> ();
}
int _tmain(int argc, _TCHAR* argv[])
{
Matrix<double> A;
Matrix<double> B;
g(A,B);
/*
error C2893: Failed to specialize function template
'Matrix<Traits< U::Type,V>::RTy pe> g(const U &,const V &)'
Notice how the template argument has changed from
Traits<typename U::Type,typenam e V::Type>
to
Traits<U::Type, V>
There is no problem if the declarations of f1 and f2 change order!!
*/
return 0;
} 3 2134
>I found the following compiler error with Microsoft Visual C++ .NET. I use different functions with return types determined by a Traits class. Function g() below works ok, but when I put the two declarations f1() and f2(), the compiler gets disturbed. The error message does not even reproduce the original code correctly. When the two declarations are switched, the problem goes away.
Benedikt,
I don't have an explanation for the curious behaviour, but trying your
code with the online Comeau compiler indicates that even without the 2
functions that confuse VC++, your code is perhaps not correct:
"ComeauTest .c", line 26: error: nontype "U::Type" is not a type name
return Matrix<U::Type> ();
changing the line:
return Matrix<U::Type> ();
to
return Matrix< typename U::Type>();
allows a clean compilation with Comeau. However it doesn't remedy the
problem that the MS compiler shows with the 2 functions where they are
in the source code. It's really strange that simply re-ordering the
functions (put g before f1 & f2 and it's alright) causes a problem and
the problem also shows in the alpha Whidbey compiler so I'll try to
report it to MS.
If this is a issue that you can't work-around, and no-one else has any
suggestions, I suggest that you telephone MS Product Support.
Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
David
Yes, I forgot the typename when making up the small example and VC++ did not
complain. My workaround in my project is an ordering that works, although it
reduces the readability.
I am quite sure it's a compiler bug but I don't know how to report this to
MS (I have a campus license). That's why I posted it here. If somebodey can
report it to MS, that would be nice.
Benedikt
"David Lowndes" <da****@example .invalid> wrote in message
news:n0******** *************** *********@4ax.c om... I found the following compiler error with Microsoft Visual C++ .NET.
I use different functions with return types determined by a Traits class. Function g() below works ok, but when I put the two declarations f1() and f2(), the compiler gets disturbed. The error message does not even
reproducethe original code correctly. When the two declarations are switched, the problem goes away.
Benedikt,
I don't have an explanation for the curious behaviour, but trying your code with the online Comeau compiler indicates that even without the 2 functions that confuse VC++, your code is perhaps not correct:
"ComeauTest .c", line 26: error: nontype "U::Type" is not a type name return Matrix<U::Type> ();
changing the line: return Matrix<U::Type> (); to return Matrix< typename U::Type>();
allows a clean compilation with Comeau. However it doesn't remedy the problem that the MS compiler shows with the 2 functions where they are in the source code. It's really strange that simply re-ordering the functions (put g before f1 & f2 and it's alright) causes a problem and the problem also shows in the alpha Whidbey compiler so I'll try to report it to MS.
If this is a issue that you can't work-around, and no-one else has any suggestions, I suggest that you telephone MS Product Support.
Dave -- MVP VC++ FAQ: http://www.mvps.org/vcfaq
>I am quite sure it's a compiler bug but I don't know how to report this to MS (I have a campus license). That's why I posted it here. If somebodey can report it to MS, that would be nice.
I've submitted a bug report for it.
Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Matthew Del Buono |
last post by:
Don't try to solve the problem. I've found a way -- around or fixing it. I'm
just curious as to whether this is Microsoft's problem in their compiler or
if there's a standard saying this is to be true (not necessarily an internal
compiler error, but still an error)
This may just a bit OT, but I decided to post it here instead of Microsoft
because my question is more directed towards standards...
Of course, any other day I would have...
|
by: Generic Usenet Account |
last post by:
Don't you often wish that compiler and linker messages for templates
were a little less cryptic and misleading?
Consider this:
I was getting this error message:
undefined reference to `vtable for <class-name>'
It turned out that I had not linked in the source for a virtual member
function. In hindsight, the message does make sense, but I must admit
that its verbiage threw me off for a while.
|
by: Mark Dufour |
last post by:
After nine months of hard work, I am proud to introduce my baby to the
world: an experimental Python-to-C++ compiler. It can convert many
Python programs into optimized C++ code, without any user intervention
such as adding type declarations. It uses rather advanced static type
inference techniques to deduce type information by itself. In
addition, it determines whether deduced types may be parameterized,
and if so, it generates...
|
by: pj |
last post by:
(Was originally, probably wrongly, posted to the vc subgroup.)
(This doesn't appear to be a c# problem, but a problem with a bug in
the Visual Studio c# compiler, but, any help will be welcome...)
Oh, I forgot to list the error messages; I would be delighted if
someone could explain how to deduce which line number in which file is
the one that the VC compiler cannot handle. Actually I'm using C#, but
the only post I could find about...
|
by: KK |
last post by:
Hello all,
I have class 'atr' which is based on templates. My idea was to
initialize it two scenarios
1. std::string case
2. other data types
I have defined the Init for the above different cases accordingly (code
shown below). However, I get compiler error. Please help me resolve
it.
Thanks.
| |
by: Steve |
last post by:
I have to develop several large and complex C++ hardware test programs that
should work under DOS, most likely with 32-bit DOS extender. Development
workstation OS would be Microsoft XP. Quite some time ago I worked in DOS,
with Borland BC++ 4.1. I do not have it any more. Which compiler would you
recommend me now? Which ones support serious DOS program development?
Criterion should be number of available free library modules (graphic menu...
|
by: Chameleon |
last post by:
This code below compiles fine with VS.2005 but with gcc 3.4.2 not.
------------------
template<class T>
static void Wastage1D::clever_erase(vector<T> &v, vector<typename
vector<T>::iterator> &its, vector<T> &vo)
{ ........ }
------------------
I run gcc like this:
gcc -c wastage1d.cpp
|
by: Miroslaw Makowiecki |
last post by:
Where can I download Comeau compiler as a trial version?
Thanks in advice.
|
by: tropos |
last post by:
I'm trying to use the 'typedef templates' idiom, mentioned in
Alexandrescu's work on templates. Here's a Dr Dobbs article from 2002
that says they are a proposed C++ standard:
http://www.ddj.com/cpp/184403850
My compiler (Visual Age C 6.0) rejects them. Are they supported? Were
they ever introduced into the language standard?
Here is an example:
|
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...
|
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,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |