g++: no vtable found for instantiation...

Jason Riedy ejr@cise.ufl.edu
Tue Jul 21 02:33:00 GMT 1998


The attached program fails to link with today's (and a prior) CVS
version:
> /usr/local/test/bin/g++ -Wall -I. -o cover_tst cover_tst.c
> Undefined			first referenced
>  symbol  			    in file
> BFS_MaxMatcher<Graph>::MaxMatcher<Graph> virtual table/var/tmp/ccSt3OJ8.o

If I instantiate BFS_MaxMatcher<Graph> by hand, the full code works.
There are also three comments pointing out other ways to get the 
program to link.  I haven't checked to see if they also get the full
code to work; they'd break the design pretty heavily.

Odd that it's looking for the virtual table of a pure abstract
base class.

Jason

---begin ``cover_tst.c''
class Graph { };

template <class _VtxType>
class matching { };

template <class _Graph >
class MaxMatcher
{
public:
  virtual void match (const _Graph& g, matching<int>& m_out) const = 0;
};

template < class _Graph >
class BFS_MaxMatcher
  : public virtual MaxMatcher<_Graph> // comment to instantiate
{
public:
  virtual void
  match (const _Graph& g, matching<int>& m_out) const { }
};

template <class _Graph>
class coverer
{
public:
  virtual void cover (const _Graph& g) const = 0;
  virtual void operator() (const _Graph& g) const { cover(g); }
};

template <class _Graph>
class DMcoverer
  : virtual public coverer<_Graph>
{
private:
  void decompose (const _Graph& g) const
    {
      BFS_MaxMatcher<_Graph> matcher;
      matching<int> m;
      matcher.match(g, m);
    }
public:
  virtual void cover (const _Graph& g) const
    { decompose (g); }
  // uncomment following line to instantiate
  //virtual void operator() (const _Graph& g) const { cover(g); }
};

int
main ()
{
  Graph bg;
  DMcoverer<Graph> coverer;
  // Swap the comments on the next two to get an instantiation...
  coverer(bg);
  //coverer.cover(bg);
}
---end ``cover_tst.c''



More information about the Gcc-bugs mailing list