I'm implementing a doubly linked list and I'm using an object of my own as the data being stored.
Here is my object:
#ifndef PLAY_H_INCLUDED
#define PLAY_H_INCLUDED
#include <string>
class Play
{
private:
int m_quarter;
int m_minutes;
std::string oTeam;
std::string dTeam;
int m_down;
int m_yardToGO;
int m_startLoc;
int playDesc;
std::string wholePlay;
int relevance;
int relCounter;
public:
int getQuarter();
int getMinutes();
std::string getoTeam();
std::string getdTeam();
int getDown();
int getYard();
int getStartLoc();
int getPlayDesc();
std::string getwholePlay();
Play(int quarter, int minutes, std::string offense, std::string defense, int dwn, int ytg, int start, int desc, std::string play, int relevance, int relCounter);
~Play();
Play parse(std::string toParse);
std::string findPlay(std::string playDesc);
};
#endif // PLAY_H_INCLUDED
-
Here is my node:
template<class T>
class node{
friend class Play;
T data;
node *next, *prev;
node(const T& t, node *n = 0, node *p = 0) {data=t; next=n; prev=p;}
};
The exact error I get is:
error: node<Play>* node<Play>::next is private.
I assume I get this problem because Play's information is private and inaccessible to node, and to fix this I tried making node a friend class of Play. When I did that I get errors saying "node is not a template type". The error makes no sense to me so I assume this isn't the way to correct my problem.
Thanks.
Use public:
above properties which should be public. If you don't specify anything, everything becomes private.
template<class T>
class node{
public: // ADD THIS
friend class Play;
T data;
node<T> *next, *prev;
node(const T& t, node<T> *n = 0, node<T> *p = 0) { // EDIT
data=t; next=n; prev=p;
}
};
Edit: You always need use <> when using template classes, like I edited in above.
All attributes in a class are private by default. Make it a struct
instead or add public:
at the beginning.
But I guess that is not the problem. When using node *next, *prev;
, use this instead:
typedef typename node<T>* MyType;
MyType *next, *prev;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.