So i have a class name repository which is just a simple array.Here is a part of the class:
template<class Element>
class repository {
private:
int size;
int capacity;
Element* elements;
I have another class named participant.I want to have a repository of participants and perform actions on that repository using a new class named controller.But I don`t know how to declare the type of the repository in the controller.
Here is a part of the class participant:
class participant {
private:
int position;
int score;
And here is a part from the class controller:
#include "repository.h"
#include "participant.h"
class controller {
private:
repository repository;
repository temporary;
void createCopy();
public:
controller();
controller(repository repo);
And I get the errors:
-invalid use of template-name ‘repository’ without an argument list int the lines with repository repository and repository temporary;
-expected ‘)’ before ‘repo’ in the line with controller(repository repo);
How should I declare the type for the repository and temporary in the declaration of class controller so that I won`t get any other errors?
Repository is a class template, so you need to declare your data members as
where
SomeTypein this case is probablyparticipant.repositoryby itself doesn’t name a type,repository<int>orrepository<std::string>etc. does. Next, your data member name cannot berepository, since that is the template name needed fortemporary. So change the name of the data member:Likewise, your constructor must take a type:
although you probably want to pass
repoby const reference: