Problem with ctor in C++
来源:互联网 发布:淘宝优惠卷无线链接 编辑:程序博客网 时间:2024/05/16 15:16
Sometimes you've got to admit that you're stupid when you did do something really stupid. I wrote some code that makes myself crashed several days ago. I mark it down now and tt can be simplified like the following:
Don't ask me why I'm too silly to write one ctor to initialize three int -_-!!, this code is just simple enough to illustrate the problem. It seems fine at the first glance but actually it may ruin your whole life especially when code go far more complicated in inheritance hierarchy. If you do not figure it out, let's look at line 5, in fact A(1, 2); doesn't do anything you expected; Unfortunately it's not a function call to initialize the this object instead it calls A::A() to initialize a temporary, local object (not this), then it immediately destructs that temporary when control flows over the ;(semicolon), this means you left a1 and a2 uninitialized. In C++ one constructor cannot call another constructor of the same class, and one of the solutions to the problem above can be:
- Problem with ctor in C++
- What happend: Exception throws in the .ctor()?
- Problem with Anonymous delegate in loop
- Problem with nutch-1.0 when run Nutch In Eclipse
- Problem of null with If statement in Mysql
- Solving the No interfaces problem with Wireshark in Ubuntu
- Problem with Cancelling a Human Task in a BPM Process
- Solving PDE problem with ODE functions in MATLAB®
- building c program with libsocket in ubuntu
- Play Objective-c with GNUstep in windows
- communicating-with-serial-port-in-C-Sharp
- Getting Started with CGI Programming in C
- Re: Programming in C with Bluetooth Sockets
- .NET Domain-Driven Design with C#: Problem - Design - Solution
- GCC 6.1 (C++17) doesn't compile std::atomic<std::chrono::system_clock::time_point> with default ctor
- Introduction to Programming in C/C with Vim
- [ Extending Lua with c/c++ ] & [ Embedding Lua in c/c++ ]
- .CTOR问题
- meet 给我分了
- android学习笔记9
- Java学习从入门到精通
- 结构化、半结构化和非结构化问题
- 不 四
- Problem with ctor in C++
- 如何实现 对输入框的文本内容进行限制的功能
- 显卡 VGA
- android 应用 电影资讯
- Java基础知识
- Fortran 输出, 在运行时决定变量所占的位置
- Tomcat环境变量配置
- tomcat6.0配置连接池
- centos安装rddtool