MarcOMorain

The code below contains a syntax error. The error message is incorrect however.

#include <cstdlib>

template <typename T> class Array
{
T* m_data;
int size;

public:

typedef T* iterator;


iterator begin ()
{
return m_data;
}

iterator end ()
{
return m_data + size;
}
};

int main (int argc, char** argv)
{
Array<float*> arr;

for (float* f = arr.begin();
f != arr.end();
f++)
{

}

return EXIT_SUCCESS;
}

The error message produced is this:

1>c:\documents and settings\marc.dub\my documents\visual studio 2005\projects\templatebug\main.cpp(28) : error C2440: 'initializing' : cannot convert from 'float *' to 'float *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\marc.dub\my documents\visual studio 2005\projects\templatebug\main.cpp(29) : error C2446: '!=' : no conversion from 'float *' to 'float *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\marc.dub\my documents\visual studio 2005\projects\templatebug\main.cpp(29) : error C2040: '!=' : 'float *' differs in levels of indirection from 'float *'

The message should say that is
cannot convert from 'float **' to 'float *'.


Is this the correct place for bug reports
Thanks,
Marc



Re: Visual C++ Language Bug with templatised typedef

Brian Kramer

I agree that this is a bug. You can report it at the Connect site:

http://connect.microsoft.com/site/sitehome.aspx SiteID=210

Thanks,

Brian





Re: Visual C++ Language Bug with templatised typedef

Marius Bancila

I agree. This seems to be buggy. A quick check on comeau shows correct error message:

Comeau C/C++ 4.3.8 (Aug 19 2006 13:36:48) for ONLINE_EVALUATION_Alpha1
Copyright 1988-2006 Comeau Computing. All rights reserved.
MODE:strict errors C++

"ComeauTest.c", line 26: error: a value of type "float **" cannot be used to
initialize an entity of type "float *"
for (float* f = arr.begin();
^

"ComeauTest.c", line 27: error: operand types are incompatible ("float *" and
"float **")
f != arr.end();
^

2 errors detected in the compilation of "ComeauTest.c".