Why don't my definitions match?

So I get the following error output on all of my functions when I try running my program:

1
2
3
4
5
6
Error	8	error C2244: 'List<T>::getLength' : unable to match function definition to an existing declaration

1>          definition
1>          'int List::getLength(void) const'
1>          existing declarations
1>          'int List<T>::getLength(void) const'


It's a template class so I have template <class T> in front of my class declaration...Why is this output telling me that List<T> is an incorrect way to define my function?
The definition should be:

1
2
3
4
5
template <class T>
int List<T>::getLength() const
{
    // ...
}
That's what I have and it's still giving me errors :\
Show me both the definition and the declaration.
int getLength() const;


1
2
3
4
5
template <typename T>
int List<T>::getLength() const
{
   return size;
}  // end getLength 
Last edited on
This minimal example works fine for me:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
template <typename T>
class List
{
        T t ;
	int length ;
public:
	int getLength() const ;
};

template <typename T>
int List<T>::getLength() const
{
	return length ;
}

int main()
{
	List<int> L ;
	int l = L.getLength() ;
}
Topic archived. No new replies allowed.