0

i have a file called arra2d.h that contains the definions of the Array2D class as shown below:

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

I want to implement all the functions in another file called array2d.hpp, how whould you do that? how the functions definions would look like? Thank you.

Stephen Newell
  • 7,330
  • 1
  • 24
  • 28
user601
  • 104
  • 6
  • 1
    Replace `.tpp` with `.hpp` in [the accepted answer of the duplicate](https://stackoverflow.com/a/495056/5470596) and you have a solution. – YSC Jan 07 '20 at 13:00
  • 1
    @YSC It seems that OP already knows about that - see the include directive at the end. They ask about the syntax. – jrok Jan 07 '20 at 13:04
  • @jrok that they can find in the duplicate's accepted answer. – YSC Jan 07 '20 at 13:05
  • 1
    @user601 `template const unsigned int Array2D::getWidth() const { /* code */ }`, for example. – jrok Jan 07 '20 at 13:06
  • @jrok when i type that it gives me error saying: Array2D is not a template. any ideas? Edit: i was forgeting the math namespace, now everything is ok. Thank you very much! :D – user601 Jan 07 '20 at 13:42
  • @user you can either reopen `namespace math` in array2d.hpp, or instead use `template const unsigned int math::Array2D::getWidth() const { /* code */ }` – Caleth Jan 07 '20 at 13:47

0 Answers0