- 用于创建主机
// host declaration
class Host : public Node {
public:
Host(uint32_t id, double rate, uint32_t queue_type, uint32_t host_type); // constructor
Queue *queue; // queue to store the packets
int host_type;
};
- 队列声明,使用deque实现
class Queue {
public:
Queue(uint32_t id, double rate, uint32_t limit_bytes, int location); // default constructor
virtual void enque(Packet *packet); // I want to call this function
};
- 创建对象并尝试将数据包推送到主机队列的主程序
# include all the .h files
using namespace std;
int main()
{
Packet P1(20.4, 1, 0, 64); // creating a packet, not shows for simplicity
Host H1(0, 20.4,1, 0); // creating my host
H1.queue->enque(P1*); // This is where I get error
// "invalid pointer". I want to push the
//packet P1 to the queue in the host,
//I am not sure how to do it.
return 0;
}
非常感谢任何帮助。谢谢,
答案 0 :(得分:0)
您需要使用H1.queue->enque(&P1);
。这将获取自动变量P1
的地址。
但请记住,只要&P1
在范围内,P1
仅有效。在生产代码中,您可能希望使用new
创建Packet
实例,并将其用作enque
的参数。