Problem with conversion operator from template class >>Text und Anhang sind VIRENFREI !!<<
b.neppert@dr-staedtler.de
b.neppert@dr-staedtler.de
Thu Jul 10 13:06:00 GMT 2003
/* Hello,
I have a problem with the compiler gcc version 3.2 20020927 (prerelease)
on Window XP.
For details please see attachment out.log in mail.
Compiling this file with
g++ -w test.cpp
results in
test.cpp: In function `int main()':
test.cpp:55: no match for `int * Wrapper<int>&' operator
Compiling this with
g++ -w -DNO_ERRORS test.cpp
works.
The define just adds an explicit cast and now the compiler can deduce how the "*" in line 63
can be compiled. So I guess the compiler can only use conversion operators
from template classes that have been instanciated at least once explicitly.
Could you please tell me if I (once again) failed to understand the standard and explain
the reasons and ramifications [what if different compilation units instantiate different
possible conversions, will this ambuguity be detected ?] for this behaviour
or if this is really a bug ?
Regards
Burkhard Neppert
b.neppert@dr-staedtler.de
*/
#include <vector>
using namespace std;
template<class T>
struct Wrapper {
Wrapper() : val() {}
Wrapper(T const & v) : val(v) {}
operator T&() { return val; }
operator T const&() const { return val; }
Wrapper & operator=(T const & rhs) {
val=rhs;
return *this;
}
T val;
};
int main() {
vector<Wrapper<int> > foo;
#if defined(NO_ERRORS)
// If we just use this conversion from Wrapper<int> => int once explicitly
// then the rest compiles OK
(int)(*foo.begin());
#endif
for(vector<Wrapper<int> >::iterator iter=foo.begin(); iter!=foo.end(); ++iter) {
(*iter)=10*(*iter)+1; // Depends on the explicit call of conversion from Wrapper<int> to int
}
return 0;
}
(See attached file: test.cpp)(See attached file: out.log)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.cpp
Type: application/octet-stream
Size: 1723 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20030710/42e8fb40/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: out.log
Type: application/octet-stream
Size: 2897 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20030710/42e8fb40/attachment-0001.obj>
More information about the Gcc-bugs
mailing list