Don't understand error - Declaring class functions
Apr 17, 2011 at 6:32pm UTC
I am getting an error in my code. I am using Visual Studio 2010, if that matters. The code is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#include "include.h"
using namespace std;
template <class T>
class vector2d
{
vector<vector<T> > _vector2d;
public :
void resize(int xSize, int ySize);
vector2d(int ,int );
};
vector2d::vector2d(int xSize, int ySize)
{
for (int w=0; w<xSize, w++)
{
_vector2d.push_back(vector<int >);
for (int h=0; h<ySize; h++)
{
_vector2d[w].push_back(0);
}
}
}
My compiler says:
error C2955: 'vector2d' : use of class template requires template argument list
see declaration of 'vector2d'
error C2955: 'vector2d' : use of class template requires template argument list
see declaration of 'vector2d'
error C2509: '{ctor}' : member function not declared in 'vector2d'
see declaration of 'vector2d'
Apr 17, 2011 at 6:57pm UTC
When you define template methods outside the class, you still need to add the template <typename T>
thing.
Apr 17, 2011 at 7:19pm UTC
Yep, that was it, thanks. For anyone who needs help in the future, here is what I changed:
1 2 3 4 5 6 7 8 9 10 11 12
template <typename T>
vector2d<T>::vector2d(int xSize, int ySize)
{
for (int w=0; w<xSize, w++)
{
_vector2d.push_back(vector<int >);
for (int h=0; h<ySize; h++)
{
_vector2d[w].push_back(0);
}
}
}
Apr 17, 2011 at 7:34pm UTC
Yeah, but that still isn't all correct.
Topic archived. No new replies allowed.