. Advertisement .
..3..
. Advertisement .
..4..
Here is the program I run:
#pragma once
template <typename ItemType>
class LinkedArrayList
{
private:
class Node {
ItemType* items;
Node* next;
Node* prev;
int capacity;
int size;
};
Node* head;
Node* tail;
int size;
public:
void insert (int index, const ItemType& item);
ItemType remove (int index);
int find (const ItemType& item);
};
#include "LinkedArrayList.h"
void LinkedArrayList::insert (int index, const ItemType& item)
{}
ItemType LinkedArrayList::remove (int index)
{return ItemType();}
int find (const ItemType& item)
{return -1;}
After I run, it returns an error:
Argument list for class template 'LinkedArrayList' is missing
Does anyone have any suggestions for the problem below: argument list for class template is missing in the cpp – How to correct it?
The cause:
You have got this error because you are trying to definite an out-of-line for a function declared in a class of template that is not correct. And those definitions is being set in a
.cpp
file. Therefore, the error happens.Solution:
Below is the way of providing a definition for a class template’s member functions:
Because the compiler won’t be able to implicitly instantiate such definitions from their point of invocation, they cannot be included in a
.cpp
file.If you use a template, mention it with your class.