• Почему возникает ошибка?

    Nightmare1
    @Nightmare1 Автор вопроса
    In file included from /usr/include/c++/12.1.0/vector:63,
                     from Machinery/Classes/../Defines/Types.h:8,
                     from Machinery/Classes/../Defines/Defines.h:15,
                     from Machinery/Classes/../Defines.h:5,
                     from Machinery/Classes/Nameable.h:6,
                     from Machinery/Classes/Node.hpp:5,
                     from Machinery/Classes/Node.cpp:1:
    /usr/include/c++/12.1.0/bits/stl_uninitialized.h: В конкретизации «constexpr bool std::__check_constructible() [с _ValueType = unique_ptr<Node*, default_delete<Node*> >; _Tp = const unique_ptr<Node*, default_delete<Node*> >&]»:
    /usr/include/c++/12.1.0/bits/stl_uninitialized.h:182:4:   требуемый из «_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [с _InputIterator = __gnu_cxx::__normal_iterator<const unique_ptr<Node*, default_delete<Node*> >*, vector<unique_ptr<Node*, default_delete<Node*> >, allocator<unique_ptr<Node*, default_delete<Node*> > > > >; _ForwardIterator = unique_ptr<Node*, default_delete<Node*> >*]»
    /usr/include/c++/12.1.0/bits/stl_uninitialized.h:372:37:   требуемый из «constexpr _ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, allocator<_Tp>&) [с _InputIterator = __gnu_cxx::__normal_iterator<const unique_ptr<Node*, default_delete<Node*> >*, vector<unique_ptr<Node*, default_delete<Node*> >, allocator<unique_ptr<Node*, default_delete<Node*> > > > >; _ForwardIterator = unique_ptr<Node*, default_delete<Node*> >*; _Tp = unique_ptr<Node*, default_delete<Node*> >]»
    /usr/include/c++/12.1.0/bits/stl_vector.h:601:31:   требуемый из «constexpr std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [с _Tp = std::unique_ptr<Node*, std::default_delete<Node*> >; _Alloc = std::allocator<std::unique_ptr<Node*, std::default_delete<Node*> > >]»
    Machinery/Classes/../Interfaces/IParentable.hpp:20:3:   требуемый из «std::vector<std::unique_ptr<_Tp> > Machinery::Interfaces::Parentable<T>::childrens() const [с T = Node*]»
    Machinery/Classes/../Interfaces/IParentable.hpp:20:3:   требуемый из «std::vector<std::unique_ptr<_Tp> > Machinery::Interfaces::Parentable<T>::get_childrens() const [с T = Node*]»
    Machinery/Classes/Node.hpp:147:88:   required from here
    /usr/include/c++/12.1.0/bits/stl_uninitialized.h:90:56: ошибка: неудача static assertion: result type must be constructible from input type
       90 |       static_assert(is_constructible<_ValueType, _Tp>::value,
          |                                                        ^~~~~
    /usr/include/c++/12.1.0/bits/stl_uninitialized.h:90:56: замечание: «std::integral_constant<bool, false>::value» evaluates to false
    In file included from /usr/include/c++/12.1.0/bits/char_traits.h:46,
                     from /usr/include/c++/12.1.0/string:40,
                     from Machinery/Classes/Nameable.h:4:
  • Почему возникает ошибка?

    Nightmare1
    @Nightmare1 Автор вопроса
    Имеет смысл тогда написать свои шаблоны
  • Почему возникает ошибка?

    Nightmare1
    @Nightmare1 Автор вопроса
    Wataru, Есть идеи по поводу возникновения ошибки?
  • Почему возникает ошибка?

    Nightmare1
    @Nightmare1 Автор вопроса
    Wataru, Обновил
  • Почему возникает ошибка?

    Nightmare1
    @Nightmare1 Автор вопроса
    Wataru, Обновил
  • Почему возникает ошибка?

    Nightmare1
    @Nightmare1 Автор вопроса
    jcmvbkbc,
    #ifndef __IDRAWABLE_H__
    #define __IDRAWABLE_H__
    
    #include "../Classes/BaseGUISegmentClass.hpp"
    
    #include <ctime>
    
    /**
     * @brief Интерфейс к объекту отображения.
     * 
     */
    class IDrawable
    {
    
        ParameterGetSetTyped(float, rendertime, .0);
        ParameterGetSetTyped(bool, visible, true);
    
        public:
            /**
             * @brief Функция тображает объект.
             * 
             */
            virtual void draw() const = 0;
    
            /**
             * @brief Функция обёртка для отображения объекта, рассчитыват времы отображения.
             * 
             */
            inline bool make_draw() {
                if (!can_draw()) return false;
                auto start = std::time(0); this->draw();
                set_rendertime(std::time(0) - start);
                return true;
            }
    
            virtual inline bool can_draw() const
            {
                if (get_visible() == true) return true;
    
                return false;
            }
    };
    
    
    #endif // __IDRAWABLE_H__


    #pragma once
    #ifndef __ISTRINGABLE_H__
    #define  __ISTRINGABLE_H__
    
    #include <string>
    #include <sstream>
    
    /**
     * @brief Интерфейс объекта который можно преобразовать в строку.
     * 
     */
    class IStringable {
    
        public:
            /**
             * @brief Получить строкое представление объекта.
             * 
             * @return std::string 
             */
            virtual std::string toString() const = 0;
    
    
            /**
             * @brief Перегрузка оператора << для вывода в std::cout <<.
             * 
             * @param os 
             * @param dt 
             * @return std::ostream& 
             */
            friend std::ostream& operator<<(std::ostream& os, const IStringable& obj)
            {
                os << obj.toString();
                return os;
            }
    };
    
    #endif // __ISTRINGABLE_H__
  • Почему возникает ошибка?

    Nightmare1
    @Nightmare1 Автор вопроса
    jcmvbkbc,
    #pragma once
    #ifndef _ISHAPE_H_
    #define _ISHAPE_H_
    
    #include "IDrawable.h"
    #include "IStringable.h"
    
    /**
     * @brief Класс прототип фигуры.
     * 
     */
    template<typename T> class IShape : public IDrawable, public IStringable
    {
        public:
            /**
             * @brief Возвращает площадь фигуры.
             * 
             * @return T 
             */
            virtual T area() = 0;
    
            /**
             * @brief Возвращает периметр фигуры.
             * 
             * @return T 
             */
            virtual T perimeter() = 0;
    
            /**
             * @brief Возвращает тоже что и perimeter.
             * 
             * @return T 
             */
            virtual inline T circumfence() { return perimeter(); }
    
            /**
             * @brief Get the Shape Name object
             * Получить название формы.
             * 
             * @return std::string 
             */
            virtual inline std::string getShapeName() = 0;
    };
    
    #endif //_ISHAPE_H_
  • Почему возникает ошибка?

    Nightmare1
    @Nightmare1 Автор вопроса
    jcmvbkbc, Реализация в cpp файле, но Adamos пролил свет, странно что нельзя разделить реализацию по файлам.
  • Почему возникает ошибка?

    Nightmare1
    @Nightmare1 Автор вопроса
    Каким образом он может быть абстрактным типом?
    #pragma once
    #ifndef __AXIS__HPP_
    #define __AXIS__HPP_
    
    #include "../../../Interfaces/IShape.h"
    
    #include "Point.hpp"
    
    /**
     * @brief Класс описывающий точку вращения объекта.
     * 
     * @tparam T 
     */
    template<typename T> class Axis : public IShape<T>
    {
      ParameterGetSetTypedClassVariable(Point2D<T>, position);
      ParameterGetSetTyped(T, rotation, 0);
    
      public:
        Axis(T rotation, Point2D<T> position);
    
        inline virtual std::string getShapeName();
        virtual void draw()  const;
        virtual inline T perimeter();
        virtual inline T area();
    };
    
    
    
    #endif // __AXIS__HPP_


    #include "Axis.hpp"
    
    
    template<typename T> Axis<T>::Axis(T rotation, Point2D<T> position)
      : __rotation(rotation)
    {
      __position.set_x(position.get_x());
      __position.set_y(position.get_y());
    }
    
    
    template<typename T> std::string Axis<T>::getShapeName()
    {
      return "axis";
    }
    
    template<typename T> void Axis<T>::draw() const
    {
      get_position().draw();
    }
    
    
    template<typename T> T Axis<T>::perimeter() {return 0;}
    template<typename T> T Axis<T>::area() {return 0;}
    
    
    TemplateClassNumericTypes(Axis);
  • Почему тут ошибка?

    Nightmare1
    @Nightmare1 Автор вопроса
    /**
     * @brief Класс точки различного числового типа.
     * 
     * @tparam T Числовой тип.
     */
    template<typename T> class Point2D : public BaseGUISegmentClass, public IShape<T>
    {
      ParameterGetSetTyped(T, x, 0);
      ParameterGetSetTyped(T, y, 0);
      public:
        Point2D();
        Point2D(T x = 0, T y = 0);
        Point2D(T x = 0);
       ~Point2D();
        DefineTypeOperators(Point2D<T>);
        DefineTypeOperatorsMainMethods(Point2D<T>);
        virtual std::string toString() const override;
        virtual void fromString(const std::string &input);
        virtual void draw() const;
        virtual T area() {return 0 ;}
        virtual T perimeter() {return 0;}
    
        virtual std::string getShapeName() {return "point";}
    };
  • Как правильно применить абстрактный класc здесь?

    Nightmare1
    @Nightmare1 Автор вопроса
    Wataru, Странно что указатели возвращаются на ура, а вот объект по стеку передать не получается.
  • Как правильно применить абстрактный класc здесь?

    Nightmare1
    @Nightmare1 Автор вопроса
    Wataru, Исправил, ошибки те же. Без модификаторов const собирается на ура.
  • Как правильно применить абстрактный класc здесь?

    Nightmare1
    @Nightmare1 Автор вопроса
    In file included from ./Machinarium/Classes/Geometry/Vector2.cpp:1:
    ./Machinarium/Classes/Geometry/Vector2.h: In instantiation of ‘class Vector2D<int>’:
    ./Machinarium/Classes/Geometry/Vector2.cpp:99:16:   required from here
    ./Machinarium/Classes/Geometry/Vector2.h:8:23: error: ‘Vector2D<T> Vector2D<T>::add_by_vector(const Vector2D<T>&) const [with T = int]’ marked ‘override’, but does not override
        8 | #define DVector(name) Vector ## name ## D
    ./Machinarium/Classes/Geometry/Vector2.cpp:22:15: note: in expansion of macro ‘DVector’
       22 | DVector(2)<T> DVector(2)<T>::add_by_vector(const DVector(2)<T>& vector2d) const
          |               ^~~~~~~
    ./Machinarium/Classes/Geometry/Vector2.h:8:23: error: ‘Vector2D<T> Vector2D<T>::sub_by_vector(const Vector2D<T>&) [with T = int]’ marked ‘override’, but does not override
        8 | #define DVector(name) Vector ## name ## D
    ./Machinarium/Classes/Geometry/Vector2.cpp:28:15: note: in expansion of macro ‘DVector’
       28 | DVector(2)<T> DVector(2)<T>::sub_by_vector(const DVector(2)<T>& vector2d)
          |               ^~~~~~~
    ./Machinarium/Classes/Geometry/Vector2.h:8:23: error: ‘bool Vector2D<T>::equals_to(const Vector2D<T>&) [with T = int]’ marked ‘override’, but does not override
        8 | #define DVector(name) Vector ## name ## D
    ./Machinarium/Classes/Geometry/Vector2.cpp:81:6: note: in expansion of macro ‘DVector’
       81 | bool DVector(2)<T>::equals_to(const DVector(2)<T>& vector2d)
          |      ^~~~~~~
    ./Machinarium/Classes/Geometry/Vector2.h:8:23: error: ‘float Vector2D<T>::distance_to(const Vector2D<T>&) [with T = int]’ marked ‘override’, but does not override
        8 | #define DVector(name) Vector ## name ## D
    ./Machinarium/Classes/Geometry/Vector2.cpp:87:7: note: in expansion of macro ‘DVector’
       87 | float DVector(2)<T>::distance_to(const DVector(2)<T>& vector2d)
          |       ^~~~~~~
    
    
    ./Machinarium/Classes/Geometry/Vector2.h:8:23: error: invalid abstract return type ‘Vector2D<int>’
        8 | #define DVector(name) Vector ## name ## D
    ./Machinarium/Classes/Geometry/Vector2.cpp:51:15: note: in expansion of macro ‘DVector’
       51 | DVector(2)<T> DVector(2)<T>::divide_by_number(T value)
          |               ^~~~~~~
    ./Machinarium/Classes/Geometry/Vector2.h:8:23: error: invalid abstract return type ‘Vector2D<int>’
        8 | #define DVector(name) Vector ## name ## D
    ./Machinarium/Classes/Geometry/Vector2.cpp:57:15: note: in expansion of macro ‘DVector’
       57 | DVector(2)<T> DVector(2)<T>::multiple_by_vector(const DVector(2)<T>& vector2d)
          |               ^~~~~~~
    ./Machinarium/Classes/Geometry/Vector2.h:8:23: error: invalid abstract return type ‘Vector2D<int>’
        8 | #define DVector(name) Vector ## name ## D
    ./Machinarium/Classes/Geometry/Vector2.cpp:63:15: note: in expansion of macro ‘DVector’
       63 | DVector(2)<T> DVector(2)<T>::divide_by_vector(const DVector(2)<T>& vector2d)
          |               ^~~~~~~
    ./Machinarium/Classes/Geometry/Vector2.cpp: In instantiation of ‘Vector2D<T> Vector2D<T>::add_by_vector(const Vector2D<T>&) const [with T = int]’:
    ./Machinarium/Classes/Geometry/Vector2.cpp:99:16:   required from here
    ./Machinarium/Classes/Geometry/Vector2.h:8:23: error: invalid abstract return type for member function ‘Vector2D<T> Vector2D<T>::add_by_vector(const Vector2D<T>&) const [with T = int]’
        8 | #define DVector(name) Vector ## name ## D
    ./Machinarium/Classes/Geometry/Vector2.cpp:22:15: note: in expansion of macro ‘DVector’
       22 | DVector(2)<T> DVector(2)<T>::add_by_vector(const DVector(2)<T>& vector2d) const
          |               ^~~~~~~
    ./Machinarium/Classes/Geometry/Vector2.h:8:23: error: invalid cast to abstract class type ‘Vector2D<int>’
        8 | #define DVector(name) Vector ## name ## D
    ./Machinarium/Classes/Geometry/Vector2.cpp:24:12: note: in expansion of macro ‘DVector’
       24 |     return DVector(2)<T>(this->get_x() + vector2d.get_x(), this->get_y() + vector2d.get_y());
          |            ^~~~~~~
    ./Machinarium/Classes/Geometry/Vector2.cpp: In instantiation of ‘Vector2D<T> Vector2D<T>::add_by_number(T) [with T = int]’:
    ./Machinarium/Classes/Geometry/Vector2.cpp:99:16:   required from here
    ./Machinarium/Classes/Geometry/Vector2.h:8:23: error: invalid abstract return type for member function ‘Vector2D<T> Vector2D<T>::add_by_number(T) [with T = int]’
        8 | #define DVector(name) Vector ## name ## D
    ./Machinarium/Classes/Geometry/Vector2.cpp:34:15: note: in expansion of macro ‘DVector’
       34 | DVector(2)<T> DVector(2)<T>::add_by_number(T value)
          |               ^~~~~~~
    ./Machinarium/Classes/Geometry/Vector2.h:8:23: error: invalid cast to abstract class type ‘Vector2D<int>’
        8 | #define DVector(name) Vector ## name ## D
    ./Machinarium/Classes/Geometry/Vector2.cpp:36:12: note: in expansion of macro ‘DVector’
       36 |     return DVector(2)<T>(this->x() + value, this->y() + value);
          |            ^~~~~~~
    ./Machinarium/Classes/Geometry/Vector2.cpp: In instantiation of ‘Vector2D<T> Vector2D<T>::sub_by_number(T) [with T = int]’:
    ./Machinarium/Classes/Geometry/Vector2.cpp:99:16:   required from here
    ./Machinarium/Classes/Geometry/Vector2.h:8:23: error: invalid abstract return type for member function ‘Vector2D<T> Vector2D<T>::sub_by_number(T) [with T = int]’
        8 | #define DVector(name) Vector ## name ## D
    ./Machinarium/Classes/Geometry/Vector2.cpp:39:36: note: in expansion of macro ‘DVector’
       39 | template<typename T> DVector(2)<T> DVector(2)<T>::sub_by_number(T value)
          |                                    ^~~~~~~
    ./Machinarium/Classes/Geometry/Vector2.h:8:23: error: invalid cast to abstract class type ‘Vector2D<int>’
        8 | #define DVector(name) Vector ## name ## D
    ./Machinarium/Classes/Geometry/Vector2.cpp:41:12: note: in expansion of macro ‘DVector’
       41 |     return DVector(2)<T>(this->x() - value, this->y() - value);
          |            ^~~~~~~
    ./Machinarium/Classes/Geometry/Vector2.cpp: In instantiation of ‘Vector2D<T> Vector2D<T>::sub_by_vector(const Vector2D<T>&) [with T = int]’:
    ./Machinarium/Classes/Geometry/Vector2.cpp:99:16:   required from here
    ./Machinarium/Classes/Geometry/Vector2.h:8:23: error: invalid abstract return type for member function ‘Vector2D<T> Vector2D<T>::sub_by_vector(const Vector2D<T>&) [with T = int]’
        8 | #define DVector(name) Vector ## name ## D
    ./Machinarium/Classes/Geometry/Vector2.cpp:28:15: note: in expansion of macro ‘DVector’
       28 | DVector(2)<T> DVector(2)<T>::sub_by_vector(const DVector(2)<T>& vector2d)
          |               ^~~~~~~
    ./Machinarium/Classes/Geometry/Vector2.cpp:30:36: error: passing ‘const Vector2D<int>’ as ‘this’ argument discards qualifiers [-fpermissive]
       30 |     return DVector(2)<T>(this->x() - vector2d.x(), this->y() - vector2d.y());
    In file included from ./Machinarium/Classes/Geometry/Vector2.h:6,
                     from ./Machinarium/Classes/Geometry/Vector2.cpp:1:
    ./Machinarium/Classes/Geometry/Vector2.h:23:29: note:   in call to ‘T Vector2D<T>::x(T) [with T = int]’
       23 |     ParameterGetSetTyped(T, x);
          |                             ^
    ./Machinarium/Classes/Geometry/../BaseGUISegmentClass.hpp:15:14: note: in definition of macro ‘ParameterGetSetTyped’
       15 |     var_type name (var_type value = 0) {            \
          |              ^~~~
    ./Machinarium/Classes/Geometry/Vector2.cpp:30:62: error: passing ‘const Vector2D<int>’ as ‘this’ argument discards qualifiers [-fpermissive]
       30 |     return DVector(2)<T>(this->x() - vector2d.x(), this->y() - vector2d.y());
    In file included from ./Machinarium/Classes/Geometry/Vector2.h:6,
                     from ./Machinarium/Classes/Geometry/Vector2.cpp:1:
    ./Machinarium/Classes/Geometry/Vector2.h:24:29: note:   in call to ‘T Vector2D<T>::y(T) [with T = int]’
       24 |     ParameterGetSetTyped(T, y);
          |                             ^
    ./Machinarium/Classes/Geometry/../BaseGUISegmentClass.hpp:15:14: note: in definition of macro ‘ParameterGetSetTyped’
       15 |     var_type name (var_type value = 0) {            \
          |              ^~~~
    In file included from ./Machinarium/Classes/Geometry/Vector2.cpp:1:
    ./Machinarium/Classes/Geometry/Vector2.h:8:23: error: invalid cast to abstract class type ‘Vector2D<int>’
    
    ./main.cpp: In function ‘int main()’:
    ./main.cpp:7:19: error: cannot declare variable ‘test’ to be of abstract type ‘Vector2D<int>’
        7 |     Vector2D<int> test(12);
          |                   ^~~~
  • Ошибка не соответствует ожиданию, почему?

    Nightmare1
    @Nightmare1 Автор вопроса
    Wataru, Получается нельзя имплементировать виртуальне функции в .cpp файлах?
    In file included from ./Machinarium/Classes/Geometry/Vector2.h:10,
                     from ./Machinarium/Classes/Geometry/Vector2.cpp:1:
    ./Machinarium/Classes/Geometry/../../Interfaces/IVector.hpp: In instantiation of ‘class Vector2D<int>’:
    ./Machinarium/Classes/Geometry/Vector2.cpp:99:16:   required from here
    ./Machinarium/Classes/Geometry/../../Interfaces/IVector.hpp:27:15: error: invalid abstract return type ‘Vector2D<int>’
       27 |     virtual C add_by_vector(const C&) = 0;
          |               ^~~~~~~~~~~~~


    template<typename T>
    class DVector(2) : public IVector<DVector(2)<T>, T>, public BaseGUISegmentClass
    {
    /**
      * @brief Класс вектора с двумя членами.
      * 
      */
    
        ParameterGetSetTyped(T, x);
        ParameterGetSetTyped(T, y);
    
    public:
       ~DVector(2)();
    
        /**
         * @brief Construct a new Vector 2 object
         * 
         * @param x Параметр Y дублируется из параметра Х.
         */
        DVector(2)(T x);
        
        /**
         * @brief Construct a new Vector 2 object
         * 
         * @param x Значение параметра Х
         * @param y Значение параметра У
         */
        DVector(2)(T x, T y);
    
    
    public:
        virtual float length();
        virtual DVector(2) add_by_vector(const DVector(2)&) const;
        virtual DVector(2) add_by_number(T);
        virtual DVector(2) sub_by_number(T);
        virtual DVector(2) sub_by_vector(const DVector(2)&);
        virtual DVector(2) multiple_by_number(T);
        virtual DVector(2) divide_by_number(T);
        virtual DVector(2) multiple_by_vector(const DVector(2)&);
        virtual DVector(2) divide_by_vector(const DVector(2)&);
        virtual float calculate_angle(const DVector(2) &);
        virtual float calculate_projection(const DVector(2)&);
        virtual bool equals_to(const DVector(2)&);
        virtual float distance_to(const DVector(2)&);
        virtual T scalar_multiply(const DVector(2)&);
    };
  • Ошибка не соответствует ожиданию, почему?

    Nightmare1
    @Nightmare1 Автор вопроса
    Wataru, Странно, имело бы место смотреть на изменчивость / не изменчивость объекта . Неконстантная функция, функция без модификатора в конце const?

    In file included from ./Machinarium/Classes/Geometry/Vector2.h:10,
                     from ./Machinarium/Classes/Geometry/Vector2.cpp:1:
    ./Machinarium/Classes/Geometry/../../Interfaces/IVector.hpp: In instantiation of ‘class Vector2D<int>’:
    ./Machinarium/Classes/Geometry/Vector2.cpp:99:16:   required from here
    ./Machinarium/Classes/Geometry/../../Interfaces/IVector.hpp:25:15: error: invalid abstract return type ‘Vector2D<int>’
       25 |     virtual C add_by_vector(const C&) = 0;


    Ещё одна ошибка.
  • VK API wall.post playlist как прикрепить?

    Nightmare1
    @Nightmare1
    Хм. Я наверное поздно. Решили проблему?
  • Ошибка не соответствует ожиданию, почему?

    Nightmare1
    @Nightmare1 Автор вопроса
    Wataru, Не меняет собственный объект или объект аргумента?