Topic: Is this a compiler bug, or am I wrong? (templates again)
Author: "Enno Rehling" <enno@uni-paderborn.de>
Date: 1997/02/20 Raw View
For some reason, depending on the compiler I use, I get an error
message on my program. The compiler that's causing my grief is g++,
while MSVC seems to do it fine, and I think Sun's CC does it, too -
have I stumbled on a compiler bug, or are the otehrs allowing me
something that I should not be allowed to do?
The code follows:
#include <vector.h>
#include <pair.h>
template <class T>
class ptr : public pair<int, T*>
{
public:
inline ptr(T &d);
inline ptr();
};
template <class T>
inline ptr<T>::ptr(T & d)
: pair<int, T*>(d.id(), (T*)0)
{
second=static_cast<T*>(d.refer_to(*this)); // 'this' doesn't exist before
}
class graph_edge;
class graph_node
{
public:
vector<ptr<graph_edge> > edges;
inline graph_edge* refer_to( graph_edge &edge );
};
class graph_edge
{
public:
vector<ptr<graph_node> > nodes;
inline graph_node* refer_to( graph_node &node );
};
And this is what g++ says:
bug.cpp: In method `ptr<graph_edge>::ptr(graph_edge &)':
bug.cpp:14: cannot lookup method in incomplete type `graph_edge'
bug.cpp:15: in base initialization for class `pair<int,graph_edge *>'
bug.cpp:16: cannot lookup method in incomplete type `graph_edge'
bug.cpp: In method `ptr<graph_node>::ptr(graph_node &)':
bug.cpp:14: no member function `graph_node::id()' defined
bug.cpp:15: in base initialization for class `pair<int,graph_node *>'
bug.cpp:16: bad argument 1 for function `class graph_edge *
graph_node::refer_to
(class graph_edge &)' (type was class ptr<graph_node>)
What's going on here?
Enno
--
Enno Rehling Kilianstra=DFe 129a 33098 Paderborn Germany
rehling@usa.net http://hrz.uni-paderborn.de/~q09960/public/
Tel/Fax: Int+ 49 (0) 5251-760796
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: Jason Merrill <jason@cygnus.com>
Date: 1997/02/22 Raw View
>>>>> Enno Rehling <enno@uni-paderborn.de> writes:
> For some reason, depending on the compiler I use, I get an error
> message on my program. The compiler that's causing my grief is g++,
> bug.cpp: In method `ptr<graph_edge>::ptr(graph_edge &)':
> bug.cpp:14: cannot lookup method in incomplete type `graph_edge'
> bug.cpp:15: in base initialization for class `pair<int,graph_edge *>'
g++ 2.7.2 instantiates class templates and their methods earlier than it
should, which can cause problems like this. This bug will be fixed in 2.8.
Jason
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]