I am trying to pass an object of Pair class into the constructor of the FollowsQuery class as shown below. I am getting a no default constructor exists error. I am not sure how to rectify this error.
This is the definition of the Pair class below in Pair.h. The object is created via a static method CreatePair.
class Pair { public: pair<DesignEntities, string> firstPair; pair<DesignEntities, string> secondPair; static Pair CreatePair(string first, string second, map<string, DesignEntities> varMap); pair<int, int> getStatementAndPos(); pair<DesignEntities, DesignEntities> getTypes(); private: Pair(pair<DesignEntities, string> first, pair<DesignEntities, string> second); }; This is my follows query class definition file. FollowsQuery.h
class FollowsQuery : Query { public: FollowsQuery(Pair pair); ~FollowsQuery(); Pair pair; // for (s1,s2) in follows(s1,s2) list<int> filterList; void setList(list<int> filteredList); // set the curr list from the prev select list<string> evaluate(PKB pkb); bool isRelatedToSelect(DesignEntities designEntity); // check if design entity was from prev select }; This is my FollowsQuery.c class file, where the error occurs.
FollowsQuery::FollowsQuery(Pair pair) { this->pair = pair; } Even though I have looked through stackoverflow and found similar questions, I have been unable to find the answer because I want to create the Pair class separately and pass it into the constructor of FollowsQuery.
Paircorrectly in the definition (implementation) of theFollowsQueryconstructor, but not in the declaration of the constructor. What are the differences between the two?Pair pairis the correct way to declare a variable (including arguments). All your other functions declare their arguments correctly, it's only the declaration of theFollowsQueryconstructor that you do it wrong. I don't want to insult you, but perhaps you should take some time to refresh some basic C++?FollowsQueryconstructor declaration stood out with its error.