www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/09/19/15:33:51

Xref: news-dnh.mv.net comp.os.msdos.djgpp:2095
Path: news-dnh.mv.net!mv!news.NH.Destek.Net!news2.net99.net!news.cais.net!ringer.cs.utsa.edu!swrinde!tank.news.pipex.net!pipex!howland.reston.ans.net!EU.net!Belgium.EU.net!chaos.kulnet.kuleuven.ac.be!verhaege
From: verhaege AT esat DOT kuleuven DOT ac DOT be (Wim Verhaegen)
Newsgroups: comp.os.msdos.djgpp
Subject: Problems with linking of pure virtual functions
Date: 18 Sep 1995 17:07:13 GMT
Organization: K.U.Leuven
Lines: 71
Nntp-Posting-Host: kwak.esat.kuleuven.ac.be
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Dj-Gateway: from newsgroup comp.os.msdos.djgpp

I'm having a problem with the linking of object code when I use
pure virtual functions. I tried the following little program:

// Start of test program

#include <iostream.h>
#include <_string.h>

class Shape
{
public:
  Shape() { n = "None"; }
  String& name() { return n; }
  const String& name() const { return n; }
  virtual double area() const = 0;
  virtual double perimeter() const = 0;
private:
  String n;
};

class Rectangle : public Shape
{
public:
  Rectangle() { h = w = 0; }
  double area() const { return h * w; }
  double perimeter() const { return 2 * (h + w); }
  double& height() { return h; }
  double height() const { return h; }
  double& width() { return w; }
  double width() const { return w; }
private:
  double h;
  double w;
};

int
main(void)
{
  Rectangle rect;
  rect.name() = "Squary";
  rect.width() = 2;
  rect.height() = 3;
  cout << "The rectangle " << rect.name() << " has height " << rect.height() << " and width " << rect.width() << endl;
  cout << "Its area is " << rect.area() << " and its perimeter " << rect.perimeter() << endl;

  cout << "\nDone.\n";
  return 0;
}

// End of test program

I have no problems with compiling this source code, but when I try to
link the object code into an executable, I get the following messages:

	test.cc(.text+0x25c): undefined reference to `__pure_virtual'
	test.cc(.text+0x264): undefined reference to `__pure_virtual'

When I checked the contents of libgpp.a with strings, I did find some
references to '___pure_virtual', with one additional underscore!

So, I'd like to know how I have to solve this. Should I tell the compiler
in some way to use an additional underscore, or am I using the wrong
compiler or library ? (I'm using GCC 2.6.8 and LIBG++ 2.6.2).


--
Wim Verhaegen                       |  All theory is grey, my friend,
Dept. of Electrical Engineering     |  And green the golden tree of life.
KU Leuven, Belgium                  |
wim DOT verhaegen AT esat DOT kuleuven DOT ac DOT be   |                              Goethe

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019