为什么构造函数没有真正运行? [英] How come a constructor not really being run?

查看:91
本文介绍了为什么构造函数没有真正运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VC ++ 2012中的解决方案包括一些可执行程序&一些DLL。其中一个项目是DataReceiver,它输出的是一个程序dataReceiver.exe。一个DLL叫做DataInterface,其输出是DataInterface.dll。



在DataReceiver的主程序中,它通过类DataInput声明一个对象DataIn,它在DataInterface项目中定义。我插入了一些日志消息然后发现了奇怪的事情:DataIn的构造函数似乎被跳过了。细节描述如下:



DataReceiver主程序的片段如下:



My solution in VC++2012 includes some executable programs & some DLLs. One of project is DataReceiver which output is a program, dataReceiver.exe. One DLL is called DataInterface, whose output is DataInterface.dll.

In main program of DataReceiver, it declares an object DataIn via class DataInput, which is defined at DataInterface project. I inserted some logging message and then found strange things happen: the DataIn's constructor seems being skipped. The detail is described as below:

The snippet of main program of DataReceiver is as below:

int main(int argc, char* argv[]) 
{
    boost::thread_group thGroup;
    boost::asio::io_service io_service;
    
    logMsg ("standebug: DataReceiver/main()\n");
    try 
    {
        logMsg ("standebug: DataReceiver/main():try\n");
        DataInput dataIn;
    
        cout << "K00.00.15.06.01\nNow:"<< boost::posix_time::to_iso_string(boost::posix_time::microsec_clock::local_time()) << endl;
        logMsg ("standebug: DataReceiver/main():to start()\n");
    
        dataIn.Start();
      ....................
    }



DataInput的构造函数以...开头:


And the DataInput's constructor begins as:

DataInput::DataInput(void)
{
    m_mode = 0;

    logMsg ("standebug: DataInput::DataInput\n");
    cout << "standebug: DataInput::DataInput\n";
    m_OnChangedFn_ptr = NULL;
    ....................
}



DataInput的方法,Start( )从以下开始:


The DataInput's method, Start() begins as:

void DataInput::Start(void)
{
    logMsg ("standebug: dataInput: Start\n");
    try
    {

    ..........
}





成功构建它们后,我在MS命令提示符下运行'DataReceiver.exe',我发现日志消息如下:





After building them successfully, I ran 'DataReceiver.exe' under MS Command Prompt, I found the logging message is as:

standebug: DataReceiver/main()
standebug: DataReceiver/main():try
standebug: DataReceiver/main():to start()





很明显,在声明DataIn之后,DataIn.DataInput()或DataIn.Start()都没有已执行,为什么?



从日志消息中,DataIn的构造函数从未运行过。为什么?



It's very obviously, after DataIn is declared, neither DataIn.DataInput() or DataIn.Start() had been executed, why?

From logging message, DataIn's constructor is never ran. How come?

推荐答案

您的构造函数可能不是默认构造函数,而是调用默认构造函数。



我也同意你可能加载错误的二进制文件的答案。尝试在main所在的应用程序中实现DataIn,它应该可以工作。
There is a chance that your constructor is not default one and default is called.

I also agree with the answer that you might load wrong binary file. Try to implement DataIn inside your application where main is located, it should work.


这篇关于为什么构造函数没有真正运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆