Template copy constructor
Feb 27, 2016 at 9:05pm UTC
I have
HashTable& operator =(const HashTable& aTable);
1 2 3 4 5 6
template <typename HashElement>
HashTable& HashTable<HashElement>::operator =(const HashTable& aTable)
{
/*Do the copy thing*/
return *this ;
}
It should be a run-able function in my opinion
1 2 3
HashTable<EngWord> hashTable;
HashTable<EngWord> hashTableA;
hashTableA = hashTable;
But it dosn't like the
**HashTable&** HashTable<HashElement>::operator =(const HashTable& aTable)
The error messages is "HashTable: super of class template requires template argument list and HashTable<HashElement>::operation=':unable to match function definition to an existing declaration
On what I've seen on the internet it should be the way I've written
Last edited on Feb 27, 2016 at 9:06pm UTC
Feb 27, 2016 at 9:28pm UTC
You parameter aTable
on line 2 of the operator=() is a HashTable... but a HashTable of what? You haven't specified.
Feb 27, 2016 at 9:39pm UTC
But the HashTable is a template and will be EngWord, as HashTable<EngWord> hashTable;
Feb 27, 2016 at 10:43pm UTC
The template argument is not implicit for the return type when defining it outside the class template definition.
1 2 3 4 5 6
template <typename HashElement>
HashTable<HashElement> & HashTable<HashElement>::operator =(const HashTable& aTable)
{
/*Do the copy thing*/
return *this ;
}
Topic archived. No new replies allowed.