首页 > 解决方案 > 如何在 hpp 文件中实现类函数?

问题描述

我有一个名为 arra2d.h 的文件,其中包含 Array2D 类的定义,如下所示:

namespace math
{

template <typename T>
class Array2D
{
protected:
    std::vector<T> buffer;
    unsigned int width, height;
public:
    const unsigned int getWidth() const;
    const unsigned int getHeight() const;
    T* getRawDataPtr();
    void setData(const T* const& data_ptr);
    T& operator () (unsigned int x, unsigned int y);
    Array2D(unsigned int width = 0, unsigned int height = 0, const T* data_ptr = 0);
    Array2D(const Array2D& src);
    ~Array2D();
    Array2D& operator = (const Array2D& right);
};
} //namespace math

/#include array2d.hpp

我想在另一个名为 array2d.hpp 的文件中实现所有功能,你应该怎么做?功能定义如何?谢谢你。

标签: c++

解决方案


推荐阅读