When I compile my program I get some warnings and a ld error. What am I wrong?
#ifndef ABSTRACTLOCATED_H
#define ABSTRACTLOCATED_H
/**
* @brief This class is the base class of any non-movable objects in 2D space (without full implementation)
* @author amreo
* @version 0.1
* @since 0.4
*/
class AbstractLocated
{
public:
/**
* @brief Return the X coordinate
* @return X coordinate
*/
virtual int x() const = 0;
/**
* @brief Return the Y coordinate
* @return Y coordinate
*/
virtual int y() const = 0;
/**
* @brief Check if the location are equal
* @param First location
* @param Second location
* @return True if are in the same location (x and y), else false
*/
static bool isLocationEqual(const AbstractLocated& loc1, const AbstractLocated& loc2)
{ return loc1.x() == loc2.x() && loc1.y() == loc2.y(); }
/**
* @brief Check if the location are equal
* @param Second location
* @return True if are in the same location (x and y), else false
*/
bool operator ==(const AbstractLocated& loc2) const
{ return x() == loc2.x() && y() == loc2.y(); }
/**
* @brief Check if the location are inequal
* @param Second location
* @return True if are in the same location (x and y), else false
*/
bool operator !=(const AbstractLocated& loc2) const
{ return x() != loc2.x() || y() != loc2.y(); }
};
#endif // ABSTRACTLOCATED_H
#ifndef ABSTRACTLOCATED_H
#define ABSTRACTLOCATED_H
/**
* @brief This class is the base class of any non-movable objects in 2D space (without full implementation)
* @author amreo
* @version 0.1
* @since 0.4
*/
class AbstractLocated
{
public:
/**
* @brief Return the X coordinate
* @return X coordinate
*/
virtual int x() const = 0;
/**
* @brief Return the Y coordinate
* @return Y coordinate
*/
virtual int y() const = 0;
/**
* @brief Check if the location are equal
* @param First location
* @param Second location
* @return True if are in the same location (x and y), else false
*/
static bool isLocationEqual(const AbstractLocated& loc1, const AbstractLocated& loc2)
{ return loc1.x() == loc2.x() && loc1.y() == loc2.y(); }
/**
* @brief Check if the location are equal
* @param Second location
* @return True if are in the same location (x and y), else false
*/
bool operator ==(const AbstractLocated& loc2) const
{ return x() == loc2.x() && y() == loc2.y(); }
/**
* @brief Check if the location are inequal
* @param Second location
* @return True if are in the same location (x and y), else false
*/
bool operator !=(const AbstractLocated& loc2) const
{ return x() != loc2.x() || y() != loc2.y(); }
};
#endif // ABSTRACTLOCATED_H
To copy to clipboard, switch view to plain text mode
#ifndef ABSTRACTMOVABLE_H
#define ABSTRACTMOVABLE_H
#include <QObject>
#include "abstractlocated.h"
/**
* @brief This class is the base class of any movable objects in 2D space (without full implementation)
* @author amreo
* @version 0.1
* @since 0.4
*/
class AbstractMovable
: virtual public AbstractLocated,
public QObject{
public:
/**
* @brief Move the coordinte by the offset loc
* @param offset x and y
*/
AbstractMovable& operator >>(const AbstractLocated& loc) { move(loc); return *this; }
/**
* @brief Move the coordinte by the offset -loc
* @param offset x and y
*/
AbstractMovable& operator <<(const AbstractLocated& loc) { move(-loc.x(), -loc.y()); return *this; }
signals:
/**
* @brief This signal is emitted whenever the location is changed
* @param New location
*/
void locationChanged(const AbstractLocated& newLocation);
public slots:
/**
* @brief Set the coordinate X
* @param New coordinte X
*/
virtual void setX(int x) = 0;
/**
* @brief Set the coordinate Y
* @param New coordinte Y
*/
virtual void setY(int y) = 0;
/**
* @brief Set the coordinate x and y
* @param New coordinate x
* @param New coordinate y
*/
virtual void setMovable(int x, int y) = 0;
/**
* @brief Set the coordinate x and y from loc
* @param Located object
*/
inline void setMovable(const AbstractLocated& loc) { setMovable(loc.x(), loc.y()); }
/**
* @brief Move the coordinate by offset
* @param offset x
* @param offset y
*/
inline void move(int offsetX, int offsetY) { setMovable(this->x()+offsetX, this->y()+offsetY); }
/**
* @brief Move the coordinate by the offset
* @param offset X and Y
*/
inline void move(const AbstractLocated& offset) { setMovable(this->x()+offset.x(), this->y()+offset.y()); }
};
#endif // ABSTRACTMOVABLE_H
#ifndef ABSTRACTMOVABLE_H
#define ABSTRACTMOVABLE_H
#include <QObject>
#include "abstractlocated.h"
/**
* @brief This class is the base class of any movable objects in 2D space (without full implementation)
* @author amreo
* @version 0.1
* @since 0.4
*/
class AbstractMovable : virtual public AbstractLocated, public QObject
{
public:
/**
* @brief Move the coordinte by the offset loc
* @param offset x and y
*/
AbstractMovable& operator >>(const AbstractLocated& loc) { move(loc); return *this; }
/**
* @brief Move the coordinte by the offset -loc
* @param offset x and y
*/
AbstractMovable& operator <<(const AbstractLocated& loc) { move(-loc.x(), -loc.y()); return *this; }
signals:
/**
* @brief This signal is emitted whenever the location is changed
* @param New location
*/
void locationChanged(const AbstractLocated& newLocation);
public slots:
/**
* @brief Set the coordinate X
* @param New coordinte X
*/
virtual void setX(int x) = 0;
/**
* @brief Set the coordinate Y
* @param New coordinte Y
*/
virtual void setY(int y) = 0;
/**
* @brief Set the coordinate x and y
* @param New coordinate x
* @param New coordinate y
*/
virtual void setMovable(int x, int y) = 0;
/**
* @brief Set the coordinate x and y from loc
* @param Located object
*/
inline void setMovable(const AbstractLocated& loc) { setMovable(loc.x(), loc.y()); }
/**
* @brief Move the coordinate by offset
* @param offset x
* @param offset y
*/
inline void move(int offsetX, int offsetY) { setMovable(this->x()+offsetX, this->y()+offsetY); }
/**
* @brief Move the coordinate by the offset
* @param offset X and Y
*/
inline void move(const AbstractLocated& offset) { setMovable(this->x()+offset.x(), this->y()+offset.y()); }
};
#endif // ABSTRACTMOVABLE_H
To copy to clipboard, switch view to plain text mode
#ifndef LOCATED_H
#define LOCATED_H
#include "src_global.h"
#include "abstractlocated.h"
/**
* @brief This class is the base class of any non-movable objects in 2D space
* @author amreo
* @version 0.2
* @since 0.1
*/
class SRCSHARED_EXPORT Located : public virtual AbstractLocated
{
public:
/**
* @brief Create a new instance of fixed position from located object
* @param Located object
*/
Located(const AbstractLocated& loc) : _x(loc.x()), _y(loc.y()) {}
/**
* @brief Copy costructor
* @param Located object
*/
Located(const Located& loc) : _x(loc.x()), _y(loc.y()) {}
/**
* @brief Return the X coordinate
* @return X coordinate
*/
inline int x() const { return _x; }
/**
* @brief Return the Y coordinate
* @return Y coordinate
*/
inline int y() const { return _x; }
protected:
/**
* @brief Coordinate x
*/
int _x;
/**
* @brief Coordinate y
*/
int _y;
/**
* @brief Create a new instance of fixed position
* @param Coordinate x
* @param Coordinate y
*/
Located(int x = 0, int y = 0) : _x(x), _y(y) {}
};
#endif // LOCATED_H
#ifndef LOCATED_H
#define LOCATED_H
#include "src_global.h"
#include "abstractlocated.h"
/**
* @brief This class is the base class of any non-movable objects in 2D space
* @author amreo
* @version 0.2
* @since 0.1
*/
class SRCSHARED_EXPORT Located : public virtual AbstractLocated
{
public:
/**
* @brief Create a new instance of fixed position from located object
* @param Located object
*/
Located(const AbstractLocated& loc) : _x(loc.x()), _y(loc.y()) {}
/**
* @brief Copy costructor
* @param Located object
*/
Located(const Located& loc) : _x(loc.x()), _y(loc.y()) {}
/**
* @brief Return the X coordinate
* @return X coordinate
*/
inline int x() const { return _x; }
/**
* @brief Return the Y coordinate
* @return Y coordinate
*/
inline int y() const { return _x; }
protected:
/**
* @brief Coordinate x
*/
int _x;
/**
* @brief Coordinate y
*/
int _y;
/**
* @brief Create a new instance of fixed position
* @param Coordinate x
* @param Coordinate y
*/
Located(int x = 0, int y = 0) : _x(x), _y(y) {}
};
#endif // LOCATED_H
To copy to clipboard, switch view to plain text mode
#ifndef MOVABLE_H
#define MOVABLE_H
#include "abstractmovable.h"
#include "located.h"
/**
* @brief This class is the base class of any movable objects in 2D space
* @author amreo
* @version 0.2
* @since 0.1
*/
class Movable : virtual public Located, virtual public AbstractMovable
{
public:
/**
* @brief Create a new instance of movable position from located object
* @param Located object
*/
explicit Movable(const AbstractMovable& loc) : Located(loc) {}
/**
* @brief Create a new instance of movable position from located object
* @param Located object
*/
explicit Movable(const Movable& loc) : Located(loc) {}
/**
* @brief Set the coordinate X
* @param New coordinte X
*/
inline void setX(int x) {_x = x; emit locationChanged(*this); }
/**
* @brief Set the coordinate Y
* @param New coordinte Y
*/
inline void setY(int y) {_y = y; emit locationChanged(*this); }
/**
* @brief Set the coordinate x and y
* @param New coordinate x
* @param New coordinate y
*/
inline void setMovable(int x, int y) {_x = x; _y = y; emit locationChanged(*this); }
protected:
/**
* @brief Create a new instance of movable position
* @param Coordinate x
* @param Coordinate y
*/
Movable(int x = 0, int y = 0) : Located(x,y) {}
};
#endif // MOVABLE_H
#ifndef MOVABLE_H
#define MOVABLE_H
#include "abstractmovable.h"
#include "located.h"
/**
* @brief This class is the base class of any movable objects in 2D space
* @author amreo
* @version 0.2
* @since 0.1
*/
class Movable : virtual public Located, virtual public AbstractMovable
{
public:
/**
* @brief Create a new instance of movable position from located object
* @param Located object
*/
explicit Movable(const AbstractMovable& loc) : Located(loc) {}
/**
* @brief Create a new instance of movable position from located object
* @param Located object
*/
explicit Movable(const Movable& loc) : Located(loc) {}
/**
* @brief Set the coordinate X
* @param New coordinte X
*/
inline void setX(int x) {_x = x; emit locationChanged(*this); }
/**
* @brief Set the coordinate Y
* @param New coordinte Y
*/
inline void setY(int y) {_y = y; emit locationChanged(*this); }
/**
* @brief Set the coordinate x and y
* @param New coordinate x
* @param New coordinate y
*/
inline void setMovable(int x, int y) {_x = x; _y = y; emit locationChanged(*this); }
protected:
/**
* @brief Create a new instance of movable position
* @param Coordinate x
* @param Coordinate y
*/
Movable(int x = 0, int y = 0) : Located(x,y) {}
};
#endif // MOVABLE_H
To copy to clipboard, switch view to plain text mode
#ifndef COORD_H
#define COORD_H
#include "movable.h"
#include <QPoint>
/**
* @brief This class rappresent a 2D coord
* @author amreo
* @version 0.2
* @since 0.1
*/
class Coord : public virtual Movable
{
Q_OBJECT
public:
/**
* @brief Costructor of coord
* @param Coordinate X
* @param Coordinate Y
* @param Parent object
*/
Coord(int x = 0, int y = 0) : Movable(x,y) {}
/**
* @brief Costructor of coord
* @param point
*/
explicit Coord(const QPoint& point) : Movable(point.x(), point.y()) {}
/**
* @brief Copy costructor of coord
* @param location
*/
Coord(const Coord& loc) : Movable(loc) {}
// /**
// * @brief Sum the left and the right
// * @param left
// * @param right
// * @return the sum of left and right
// */
// static inline Coord sum(const AbstractLocated& left, const AbstractLocated& right)
// { return Coord(left.x()+right.x(), left.y()+right.y()); }
signals:
public slots:
};
#endif // COORD_H
#ifndef COORD_H
#define COORD_H
#include "movable.h"
#include <QPoint>
/**
* @brief This class rappresent a 2D coord
* @author amreo
* @version 0.2
* @since 0.1
*/
class Coord : public virtual Movable
{
Q_OBJECT
public:
/**
* @brief Costructor of coord
* @param Coordinate X
* @param Coordinate Y
* @param Parent object
*/
Coord(int x = 0, int y = 0) : Movable(x,y) {}
/**
* @brief Costructor of coord
* @param point
*/
explicit Coord(const QPoint& point) : Movable(point.x(), point.y()) {}
/**
* @brief Copy costructor of coord
* @param location
*/
Coord(const Coord& loc) : Movable(loc) {}
// /**
// * @brief Sum the left and the right
// * @param left
// * @param right
// * @return the sum of left and right
// */
// static inline Coord sum(const AbstractLocated& left, const AbstractLocated& right)
// { return Coord(left.x()+right.x(), left.y()+right.y()); }
signals:
public slots:
};
#endif // COORD_H
To copy to clipboard, switch view to plain text mode
#include "coord.h"
int main()
{
Coord l(0,0);
}
#include "coord.h"
int main()
{
Coord l(0,0);
}
To copy to clipboard, switch view to plain text mode
Errors/Warnings:
In file included from ../build/moc/moc_coord.cpp:9:0:
../build/moc/../../../gridb/src/coord.h: In copy constructor 'Coord::Coord(const Coord&)':
../build/moc/../../../gridb/src/coord.h:34:9: warning: base class 'class Located' should be explicitly initialized in the copy constructor [-Wextra]
Coord(const Coord& loc) : Movable(loc) {}
^
In file included from ../../gridb/test/tests.h:8:0,
from ../../gridb/test/main.cpp:2:
../../gridb/src/coord.h: In copy constructor 'Coord::Coord(const Coord&)':
../../gridb/src/coord.h:34:9: warning: base class 'class Located' should be explicitly initialized in the copy constructor [-Wextra]
Coord(const Coord& loc) : Movable(loc) {}
^
In file included from ../../gridb/test/tests.h:8:0,
from moc_tests.cpp:9:
../../gridb/src/coord.h: In copy constructor 'Coord::Coord(const Coord&)':
../../gridb/src/coord.h:34:9: warning: base class 'class Located' should be explicitly initialized in the copy constructor [-Wextra]
Coord(const Coord& loc) : Movable(loc) {}
^
/home/amreo/src/repo/gridb/build-gridb-Desktop-Debug/test/../bin//libgridb.so: undefined reference to `AbstractMovable::locationChanged(AbstractLocated const&)'
collect2: error: ld returned 1 exit status
In file included from ../build/moc/moc_coord.cpp:9:0:
../build/moc/../../../gridb/src/coord.h: In copy constructor 'Coord::Coord(const Coord&)':
../build/moc/../../../gridb/src/coord.h:34:9: warning: base class 'class Located' should be explicitly initialized in the copy constructor [-Wextra]
Coord(const Coord& loc) : Movable(loc) {}
^
In file included from ../../gridb/test/tests.h:8:0,
from ../../gridb/test/main.cpp:2:
../../gridb/src/coord.h: In copy constructor 'Coord::Coord(const Coord&)':
../../gridb/src/coord.h:34:9: warning: base class 'class Located' should be explicitly initialized in the copy constructor [-Wextra]
Coord(const Coord& loc) : Movable(loc) {}
^
In file included from ../../gridb/test/tests.h:8:0,
from moc_tests.cpp:9:
../../gridb/src/coord.h: In copy constructor 'Coord::Coord(const Coord&)':
../../gridb/src/coord.h:34:9: warning: base class 'class Located' should be explicitly initialized in the copy constructor [-Wextra]
Coord(const Coord& loc) : Movable(loc) {}
^
/home/amreo/src/repo/gridb/build-gridb-Desktop-Debug/test/../bin//libgridb.so: undefined reference to `AbstractMovable::locationChanged(AbstractLocated const&)'
collect2: error: ld returned 1 exit status
To copy to clipboard, switch view to plain text mode
Bookmarks