Results 1 to 4 of 4

Thread: [c++] ambiguos base

  1. #1
    Join Date
    Aug 2015
    Posts
    14
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Android
    Thanks
    1

    Exclamation [c++] ambiguos base

    I've a error: movable.h:14: error: 'AbstractLocated' is an ambiguous base of 'Movable'
    void setX(int x) {_x = x; emit locationChanged(*this); }
    (similiar for other function)

    Why?

    Qt Code:
    1. #ifndef ABSTRACTLOCATED_H
    2. #define ABSTRACTLOCATED_H
    3.  
    4. /**
    5.  * @brief This class is the base class of any non-movable objects in 2D space (without full implementation)
    6.  * @author amreo
    7.  * @version 0.1
    8.  * @since 0.4
    9.  */
    10. class AbstractLocated
    11. {
    12. public:
    13.  
    14. /**
    15. * @brief Return the X coordinate
    16. * @return X coordinate
    17. */
    18. virtual int x() const = 0;
    19. /**
    20. * @brief Return the Y coordinate
    21. * @return Y coordinate
    22. */
    23. virtual int y() const = 0;
    24.  
    25. /**
    26. * @brief Check if the location are equal
    27. * @param First location
    28. * @param Second location
    29. * @return True if are in the same location (x and y), else false
    30. */
    31. static bool isLocationEqual(const AbstractLocated& loc1, const AbstractLocated& loc2)
    32. { return loc1.x() == loc2.x() && loc1.y() == loc2.y(); }
    33.  
    34. /**
    35. * @brief Check if the location are equal
    36. * @param Second location
    37. * @return True if are in the same location (x and y), else false
    38. */
    39. bool operator ==(const AbstractLocated& loc2) const
    40. { return x() == loc2.x() && y() == loc2.y(); }
    41.  
    42. /**
    43. * @brief Check if the location are inequal
    44. * @param Second location
    45. * @return True if are in the same location (x and y), else false
    46. */
    47. bool operator !=(const AbstractLocated& loc2) const
    48. { return x() != loc2.x() || y() != loc2.y(); }
    49. };
    50.  
    51. #endif // ABSTRACTLOCATED_H
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #ifndef ABSTRACTMOVABLE_H
    2. #define ABSTRACTMOVABLE_H
    3. #include <QObject>
    4. #include "abstractlocated.h"
    5.  
    6. /**
    7.  * @brief This class is the base class of any movable objects in 2D space (without full implementation)
    8.  * @author amreo
    9.  * @version 0.1
    10.  * @since 0.4
    11.  */
    12. class AbstractMovable : public AbstractLocated, QObject
    13. {
    14. public:
    15.  
    16. /**
    17. * @brief Move the coordinte by the offset loc
    18. * @param offset x and y
    19. */
    20. AbstractMovable& operator >>(const AbstractLocated& loc) { move(loc); return *this; }
    21. /**
    22. * @brief Move the coordinte by the offset -loc
    23. * @param offset x and y
    24. */
    25. AbstractMovable& operator <<(const AbstractLocated& loc) { move(-loc.x(), -loc.y()); return *this; }
    26.  
    27. signals:
    28. /**
    29. * @brief This signal is emitted whenever the location is changed
    30. * @param New location
    31. */
    32. void locationChanged(const AbstractLocated& newLocation);
    33.  
    34. public slots:
    35. /**
    36. * @brief Set the coordinate X
    37. * @param New coordinte X
    38. */
    39. virtual void setX(int x) = 0;
    40. /**
    41. * @brief Set the coordinate Y
    42. * @param New coordinte Y
    43. */
    44. virtual void setY(int y) = 0;
    45. /**
    46. * @brief Set the coordinate x and y
    47. * @param New coordinate x
    48. * @param New coordinate y
    49. */
    50. virtual void setMovable(int x, int y) = 0;
    51. /**
    52. * @brief Set the coordinate x and y from loc
    53. * @param Located object
    54. */
    55. inline void setMovable(const AbstractLocated& loc) { setMovable(loc.x(), loc.y()); }
    56.  
    57. /**
    58. * @brief Move the coordinate by offset
    59. * @param offset x
    60. * @param offset y
    61. */
    62. inline void move(int offsetX, int offsetY) { setMovable(this->x()+offsetX, this->y()+offsetY); }
    63. /**
    64. * @brief Move the coordinate by the offset
    65. * @param offset X and Y
    66. */
    67. inline void move(const AbstractLocated& offset) { setMovable(this->x()+offset.x(), this->y()+offset.y()); }
    68.  
    69. };
    70.  
    71. #endif // ABSTRACTMOVABLE_H
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #ifndef LOCATED_H
    2. #define LOCATED_H
    3.  
    4. #include "src_global.h"
    5. #include "abstractlocated.h"
    6.  
    7. /**
    8.  * @brief This class is the base class of any non-movable objects in 2D space
    9.  * @author amreo
    10.  * @version 0.2
    11.  * @since 0.1
    12.  */
    13. class SRCSHARED_EXPORT Located : public AbstractLocated
    14. {
    15.  
    16. public:
    17. /**
    18. * @brief Create a new instance of fixed position from located object
    19. * @param Located object
    20. */
    21. Located(const AbstractLocated& loc) : _x(loc.x()), _y(loc.y()) {}
    22.  
    23. /**
    24. * @brief Return the X coordinate
    25. * @return X coordinate
    26. */
    27. inline int x() const { return _x; }
    28. /**
    29. * @brief Return the Y coordinate
    30. * @return Y coordinate
    31. */
    32. inline int y() const { return _x; }
    33.  
    34. protected:
    35. /**
    36. * @brief Coordinate x
    37. */
    38. int _x;
    39. /**
    40. * @brief Coordinate y
    41. */
    42. int _y;
    43.  
    44. /**
    45. * @brief Create a new instance of fixed position
    46. * @param Coordinate x
    47. * @param Coordinate y
    48. */
    49. Located(int x = 0, int y = 0) : _x(x), _y(y) {}
    50. };
    51.  
    52. #endif // LOCATED_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #ifndef MOVABLE_H
    2. #define MOVABLE_H
    3. #include "abstractmovable.h"
    4. #include "located.h"
    5.  
    6. class Movable : virtual public Located, virtual public AbstractMovable
    7. {
    8. public:
    9.  
    10. /**
    11. * @brief Set the coordinate X
    12. * @param New coordinte X
    13. */
    14. void setX(int x) {_x = x; emit locationChanged(*this); }
    15. /**
    16. * @brief Set the coordinate Y
    17. * @param New coordinte Y
    18. */
    19. void setY(int y) {_y = y; emit locationChanged(*this); }
    20. /**
    21. * @brief Set the coordinate x and y
    22. * @param New coordinate x
    23. * @param New coordinate y
    24. */
    25. void setMovable(int x, int y) {_x = x; _y = y; emit locationChanged(*this); }
    26. };
    27.  
    28. #endif // MOVABLE_H
    To copy to clipboard, switch view to plain text mode 

    Why?

  2. #2
    Join Date
    Mar 2011
    Posts
    25
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    2

    Default Re: [c++] ambiguos base

    Located and AbstractMovable have to be ihnerited with virtual keyword as well.

  3. #3
    Join Date
    Aug 2015
    Posts
    14
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Android
    Thanks
    1

    Default Re: [c++] ambiguos base

    Thanks 10^3

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: [c++] ambiguos base

    Also inherit from QObject publically if you want to use this as a QObject (e.g in connect()) and make the class inherit from QObject first, MOC only checks the first base class.

    Cheers,
    _

Similar Threads

  1. base address of library
    By tuli in forum Qt Programming
    Replies: 1
    Last Post: 22nd October 2013, 22:50
  2. data base in qt
    By Fafa in forum Qt Programming
    Replies: 2
    Last Post: 15th June 2011, 01:52
  3. How to get the base parent Widget
    By vaibhav in forum Qt Programming
    Replies: 8
    Last Post: 15th February 2011, 12:27
  4. very very base question
    By mickey in forum General Programming
    Replies: 12
    Last Post: 26th March 2008, 23:01
  5. pointer base problem
    By mickey in forum General Programming
    Replies: 2
    Last Post: 7th November 2007, 22:36

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.