`

C++ - autogenerated copy constructor and assignment operator gotchas

    博客分类:
  • c++
c++ 
阅读更多

It has been changed that the semantic of the copy constructor and the assignment operator in the relationship with class hierarhcy from vs10 to vs12...
one case of the gotchas is like this:

#include <iostream>
struct A
{
  A& operator=(const A&) { return *this; }
  template <typename T> A& operator=(const T&) // while one can argue that this is the desired semantic, B will continue to search its parent's definition if there is none provided 
  {
    std::cout << "This should not be printed" << std::endl;
    return *this;
  }
};

struct B : A { };



int _tmain(int argc, _TCHAR* argv[])
{
	  B x;
  B y;
  x = y;
 return 0;
}

 

 

You will see the output "This should not be printed" printed. but if you run the same code in VS 2012, you won't see it. 

if you change the main to this:

int _tmain(int argc, _TCHAR* argv[])
{
	 // B x;
  //B y;
  //x = y;

  A x ;
  A y ;
  y = x;
 return 0;

you will NOT see the output "This should not be printed" printed.

 

I guess it is because in VS2010, it is deemed right to go the parent's scope when resolving copy constructor or assignment operator before it auto generate the constructor or assignment operator... And now this has been changed because this is too dangerous?

 

 

分享到:
评论

相关推荐

    rdpwrap.ini 配置文件 ver.10.0.20.*

    每个`10.0.20*.*-autogenerated.ini`文件代表了一个特定的Windows 10版本,例如10.0.20241.1000等,这些文件包含了针对这些特定版本的RDP服务端口的Patched status和NotPatched status信息。 **如何使用rdpwrap.ini...

    Windows远程RDPWrap[10.0.17763.2628]配置文件.ini

    Windows RDPwarp 配置文件主要用于windows远程使用,接触windows系统远程限制和远程用户数量配置,下载该配置文件后,直接替换C:Program FilesRDP *目录下的ini配置文件,然后重启RDP服务即可,如果有不懂得,可以...

    inject.cpp.x64_86.so:在x64_86平台上挂钩共享库和虚拟对象的调用

    inject.h - autogenerated by do script file with description for functions and methods classes - class names for do script for generation inject.h lib.h - define inteface of test library lib.cpp - ...

    PyPI 官网下载 | autogenerated_api-1.1.2-py2.py3-none-any.whl

    标题中的“PyPI 官网下载 | autogenerated_api-1.1.2-py2.py3-none-any.whl”指的是在Python的包索引服务(Python Package Index,简称PyPI)上发布的名为`autogenerated_api`的软件包的一个版本,版本号为1.1.2。...

    rdpwrap.ini 配置文件 ver.10.0.17.*

    例如,10.0.17763.1369-autogenerated.ini代表的是Windows 10 Version 1809 (Build 17763.1369)的配置。ini文件中包含了这些特定版本下启用无限制RDP的注册表键和值。 **配置过程**: 1. **备份原始配置**:在替换...

    开源项目-gernest-qlfu.zip

    开源项目-gernest-qlfu.zip,gernest/qlfu[a.k.a ql-Fun] : autogenerated magic crud and restful api for experimenting with ql database

    rdpwrap.ini 配置文件 ver.10.0.18.*

    这些"autogenerated"文件名表明它们是根据特定Windows更新自动生成的,确保覆盖了对应版本中的RDP服务端点。 安装和使用RDPWrap的步骤大致如下: 1. **下载与系统版本匹配的rdpwrap.ini文件**:首先,需要确定你的...

    SignalR 2.0 and MVC 5即时通讯完整版示例

    --Reference the autogenerated SignalR hub script. --&gt; [removed][removed] &lt;!--SignalR script to update the chat page and send messages.--&gt; [removed] $(function () { // Reference the...

    Go-具有自动生成证书的单命令SSL反向代理LetsEncrypt自签名提供

    Single-command SSL reverse proxy with autogenerated certificates (LetsEncrypt, self-signed, provided)

    google api php client

    And then browsing to the host and port you specified (in the above example, `http://localhost:8000`). ### Basic Example ### ```php // include your composer dependencies require_once 'vendor/autoload...

    u-boot makefile分析

    - 创建版本信息文件 `version_autogenerated.h`。 - **主机架构信息**: - 输出当前主机架构 `HOSTARCH` 和操作系统 `HOSTOS`。 - **构建目录处理**: - 检测是否指定了独立的构建目录 (`BUILD_DIR`)。 - 如果没有...

    after-effects-script-snippets, 在效果之后,这是 js Fragment的松散集合.zip

    after-effects-script-snippets, 在效果之后,这是 js Fragment的松散集合 after-effects-script-snippets这是一个 js Fragment的松散集合,之后##Autogenerated 目录### __movetotop.jsx/**@author fabianthebli

    ZTK-开源

    8. **delete-autogenerated.sh**:这可能是一个清理脚本,用于删除由构建过程生成的临时或自动生成的文件。 9. **whattodo.sh**:类似于TODO文件,可能是另一种形式的任务列表,指导开发者参与项目的工作。 10. **...

    cordova 热更新

    "autogenerated": true, "update": "start", "content_url": "http://192.168.1.34:8080/myApp/www/" } 的 地址改为自己的 地址 第四步、将android项目导入Android Studio 第五步、 myApp\platforms\android\...

    粗略使用cocostudio制作的scrollview

    导出的文件通常会包含一个Resources文件夹,里面包含所有图片、精灵表和XML配置文件,以及一个Classes文件夹,其中包含AutoGenerated的C++或Lua代码,用于在cocos2d-x项目中实例化UI。 在cocos2d-x项目中,你需要将...

    Driver Annotations in Depth - Part 2 - Slides - 2008 (dde-t676_d

    8. **代码生成**:某些注解能够触发工具自动生成代码,例如,`@ autogenerated` 可能用于自动创建设备注册或I/O处理代码。 9. **最佳实践**:讲座可能分享了如何有效地使用注解,避免滥用或过度依赖,以保持代码...

    Android代码-kodable

    autogenerated code manually write custom coders/decoder Features: Generated code does not use any kind of reflection in runtime It's fast in runtime, very fast Compile time check for kodables - if ...

    mongoose-api-generator:从您的Mongoose模型自动生成REST API

    猫鼬REST API自动生成器从Mongoose模型自动...DIR = ' models '# the path of the autogenerated resources enum file for the client (optional)# ./client/src by defaultRESOURCES_FILE_DIR = ' client/src '然后

Global site tag (gtag.js) - Google Analytics