multiple definition of operator<< ?
Thorsten Gecks
t_gecks@informatik.uni-kl.de
Sun Dec 10 06:17:00 GMT 2000
Hello, I'm programming a bigger project and recently I tried to print a
simple internal type on cout. For this reason I wrote and operator<< for
the simple type:
ifndef KSIMONSTRUCTS_HH
#define KSIMONSTRUCTS_HH
#include <utility>
#include <ostream.h>
namespace KSimoN {
struct DocUnitPosition
{
int x;
int y;
int z;
};
} // End of namespace
ostream & operator<<(ostream & os, const KSimoN::DocUnitPosition & pos)
{
return os << '(' << pos.x << ',' << pos.y << ',' << pos.z << ')';
}
#endif
Now, here is my problem: ###########
Compiling my programm, I get the following error:
/home/student/programmieren/ksimon/ksimon/view2dnormalzplane.h(.text+0x0):
multiple definition of `operator<<(ostream &,
KSimoN::DocUnitPosition const &)'
view2dnormalnormalunit.o(.text+0x0):/usr/include/g++-3/stl_alloc.h:
first defined here
collect2: ld returned 1 exit status
I don't understand that, since I do define this operator only in the file
printed above. (I'm using Mandrake 7.1 and got libstdc++-devel from their
ftp-server.) Here is in addition view2dnormalzplane.h:
ifndef KSIMONVIEW2DNORMALZPLANE_H
#define KSIMONVIEW2DNORMALZPLANE_H
#include <memory>
#include <qwidget.h>
#include <qobjectlist.h>
#include <structs.h> // this file contains the struct and the
// operator<< ######################
#include <view2dnormalabstractbase.h>
namespace KSimoN {
class View2DNormalZPlane : public QWidget, public View2DNormalAbstractBase
{
Q_OBJECT
public:
View2DNormalZPlane( QWidget * parent, const char * name, int wflags,
DocUnitLocator * unitLocatorArg = 0);
~View2DNormalZPlane();
bool drawLink(View2DAbstractUnit * source, View2DAbstractUnit * target)
{ return true; } // not implemented yet
protected:
auto_ptr<QObjectList> selectedChilds(const QRect & selection) const;
private:
void placeUnits(pair<DocUnitPosition, DocUnitPosition> &
minMaxOfNetwork);
};
} // End of namespace
#endif
More information about the Libstdc++
mailing list