错误:不能调用构造函数
Error: cannot call constructor
我在ns2中加入了新的模块来评估视频传输。我对agent.h,agent等文件做了一些需要的修改。抄送、制作文件等。在犯错误的过程中。错误是:
myevalvid/myudp.cc: In member function ‘virtual void myUdpAgent::sendmsg(int, AppData*, const char*)’:
myevalvid/myudp.cc:56:123: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘long unsigned int’ [-Wformat]
myevalvid/myudp.cc:78:123: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘long unsigned int’ [-Wformat]
make: *** No rule to make target `myevalvid/myevalvid_sink.o ', needed by `ns'. Stop.
代码
#include "myudp.h"
#include "rtp.h"
#include "random.h"
#include "address.h"
#include "ip.h"
static class myUdpAgentClass : public TclClass {
public:
myUdpAgentClass() : TclClass("Agent/myUDP") {}
TclObject* create(int, const char*const*) {
return (new myUdpAgent());
}
} class_myudp_agent;
myUdpAgent::myUdpAgent() : id_(0), openfile(0)
{
bind("packetSize_", &size_);
}
void myUdpAgent::sendmsg(int nbytes, AppData* data, const char* flags)
{
Packet *p;
int n;
char buf[100]; //added by smallko
if (size_)
n = nbytes / size_;
else
printf("Error: myUDP size = 0n");
if (nbytes == -1) {
printf("Error: sendmsg() for UDP should not be -1n");
return;
}
// If they are sending data, then it must fit within a single packet.
if (data && nbytes > size_) {
printf("Error: data greater than maximum myUDP packet sizen");
return;
}
double local_time = Scheduler::instance().clock();
while (n-- > 0) {
p = allocpkt();
hdr_cmn::access(p)->size() = size_;
hdr_rtp* rh = hdr_rtp::access(p);
rh->flags() = 0;
rh->seqno() = ++seqno_;
hdr_cmn::access(p)->timestamp() =
(u_int32_t)(SAMPLERATE*local_time);
hdr_cmn::access(p)->sendtime_ = local_time; // (smallko)
if(openfile!=0){
hdr_cmn::access(p)->frame_pkt_id_ = id_++;
sprintf(buf, "%-16f id %-16d udp %-16dn", local_time, hdr_cmn::access(p)->frame_pkt_id_, hdr_cmn::access(p)->size()-28);
fwrite(buf, strlen(buf), 1, BWFile);
//printf("%-16f id %-16d udp %-16dn", local_time, hdr_cmn::access(p)->frame_pkt_id_, hdr_cmn::access(p)->size()-28);
}
// add "beginning of talkspurt" labels (tcl/ex/test-rcvr.tcl)
if (flags && (0 ==strcmp(flags, "NEW_BURST")))
rh->flags() |= RTP_M;
p->setdata(data);
target_->recv(p);
}
n = nbytes % size_;
if (n > 0) {
p = allocpkt();
hdr_cmn::access(p)->size() = n;
hdr_rtp* rh = hdr_rtp::access(p);
rh->flags() = 0;
rh->seqno() = ++seqno_;
hdr_cmn::access(p)->timestamp() =
(u_int32_t)(SAMPLERATE*local_time);
hdr_cmn::access(p)->sendtime_ = local_time; // (smallko)
if(openfile!=0){
hdr_cmn::access(p)->frame_pkt_id_ = id_++;
sprintf(buf, "%-16f id %-16d udp %-16dn", local_time, hdr_cmn::access(p)->frame_pkt_id_, hdr_cmn::access(p)->size()-28);
fwrite(buf, strlen(buf), 1, BWFile);
//printf("%-16f id %-16d udp %-16dn", local_time, hdr_cmn::access(p)->frame_pkt_id_, hdr_cmn::access(p)->size()-28);
}
// add "beginning of talkspurt" labels (tcl/ex/test-rcvr.tcl)
if (flags && (0 == strcmp(flags, "NEW_BURST")))
rh->flags() |= RTP_M;
p->setdata(data);
target_->recv(p);
}
idle();
}
int myUdpAgent::command(int argc, const char*const* argv)
{
if(argc ==2) { //added by smallko
if (strcmp(argv[1], "closefile") == 0) {
if(openfile==1)
fclose(BWFile);
return (TCL_OK);
}
}
if (argc ==3) { //added by smallko
if (strcmp(argv[1], "set_filename") == 0) {
strcpy(BWfile, argv[2]);
BWFile = fopen(BWfile, "w");
openfile=1;
return (TCL_OK);
}
}
return (UdpAgent::command(argc, argv));
}
请帮我整理一下这个错误
正如错误提示的那样,您不能直接调用构造函数,因为这一行似乎试图这样做:
UdpAgent::UdpAgent();
你可能只是想删除那一行。该构造函数已经在构造函数的开头被(隐式地)调用。你可以把UdpAgent()
放在初始化列表的开头,如果你想明确它的话。
相关文章:
- 获取从C++中同一类中的构造函数调用的方法返回的值
- 从具有按值捕获的 lambda 移动构造 std::函数时,移动构造函数调用两次
- 确保所有构造函数调用相同的函数 c++ 设计模式
- 减少复制构造函数调用
- 使用回调函数从构造函数调用虚拟/派生方法的替代方法?
- 在 Google 测试中,我可以从构造函数调用 GetParam() 吗?
- C++ - 从另一个类构造函数调用类构造函数
- 在C++中初始化带有和不使用构造函数调用的对象有什么区别
- 是否可以从移动构造函数调用默认构造函数?
- 在模板生成器模式中分解重复的构造函数调用
- std::atexit 从全局对象的构造函数调用时的排序
- 对构造函数调用的约束
- 编译器错过了无效的构造函数调用,并调用不存在的(或私有的)默认构造函数
- 用构造函数调用填充向量
- 创建指针时是否没有构造函数调用
- 使用 emplace_back 避免移动构造函数调用的最佳方法?
- C++ 抽象类构造函数调用
- 为什么函数参数将带有参数的构造函数调用
- 为什么比“构造函数”调用更多的“解构器”调用
- 将对象传递给函数并不是导致构造函数调用