- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
根据标准:
A copy/move constructor for class X is trivial if it is not user-provided and if
— class X has no virtual functions (10.3) and no virtual base classes (10.1), and
— the constructor selected to copy/move each direct base class subobject is trivial, and
— for each non-static data member of X that is of class type (or array thereof), the constructor selected to copy/move that member is trivial;
otherwise the copy/move constructor is non-trivial.
我认为该标准引入了“trival cp/mv ctor”的概念来推断您可以只使用 std::memcpy 复制类而不是调用构造函数,并且不会有未定义的行为。
但是,标准不允许存在虚函数,我认为虚函数有违“trival cp/mv ctor”的精神。具有指向虚函数的 vtable 的类仍然可以使用 std::memcpy 进行复制并且具有正确的行为。毕竟,您不能在运行时更改类的 vtable——这会破坏此类的其他实例。
那么,为什么没有用户提供的 cp/mv ctor 和具有虚函数但没有虚拟基的类不能有“trival cp/mv ctor”?
最佳答案
这不是一个简单的类型,因为确保“vptr”指向正确的“vtable”并不像复制指针的值那么简单。我们可以复制出只是基础子对象。我们不需要总是处理最派生的对象类型。
void bar(base const& b) {
b.overriden_function();
}
void foo(base const& b) {
auto other_b = b;
bar(other_b);
}
int main() {
derived d;
foo(d);
}
让我们假设 base
是微不足道的。这样copy就照你说的做了。 b
的 vptr 指向 derived
的 vtable。所以现在我们获得了一个对象,它的 vtpr 指向了错误的 vtable。我们调用一个覆盖函数。
轰!
关于c++ - 为什么没有用户提供 cp/mv ctor 并具有虚函数但没有虚拟基的类没有 "trival cp/mv ctor"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49473684/
我最近尝试将我的个人博客网站部署到我的远程服务器。当我尝试通过执行 mv 将一些文件和目录移动到另一个位置时,发生了一些意外的错误。命令行回显“目录不为空”。进行一些谷歌搜索后,我再次尝试使用“-f”
我有一个跟踪的foo。现在,因为我心不在焉,所以我跑了: mv foo bar 现在,当我执行 hg st 时,我得到: ! foo ? bar 我想追溯修复这个问题——就好像我做了一个hg mv f
运行 mv 命令但没有任何反应,所以我尝试安装它: # yum install mv 然后我得到了 Nothing to do 响应错误:没有可用的包 mv 有关如何在 Centos 6 上的 Apa
对于源代码控制系统,运行如下命令之间的实际结果有何不同: git mv # see: https://git-scm.com/docs/git-mv 与像“较低”级别的命令相比 mv 从版本
我偶然发现有人在 makefile 目标中将 mv 命令更改为 -mv。有什么区别? %/install-stamp:
Cassandra 的 MV 尚未准备就绪: Cassandra Materialized views impact 限制:https://docs.datastax.com/en/cql-oss/3
我有 azure 存储帐户,并且在单个文件夹中有一些文件(超过数百万个文件)。我想使用 dbutils.fs.mv 到另一个文件夹。最快的方法是什么? 最佳答案 您可以尝试以下方法。 azcopy正如
我正在尝试编写一个 shell 脚本,用户输入他们想要重命名为第一个变量的文件,然后输入他们想要的第二个变量的新名称。程序给出的唯一输出是 mv 缺少文件操作数。我已经碰壁了,目前没有什么可以尝试的。
根据标准: A copy/move constructor for class X is trivial if it is not user-provided and if — class X has
我想将在 jenkins 作业中创建的所有 JSON 文件移动到不同的文件夹。 作业可能没有创建任何 json 文件。在这种情况下,mv 命令会引发错误,因此作业会失败。 如果找不到文件,如何防止 m
当使用 git mv 重命名文件时,提交将显示重命名自和重命名为,并且在 pull 请求中显示相同,这很好。但是当一个文件是 git mv ed然后更改,看起来有一定的阈值,当更改的行数超过它时,它将
我的部分脚本是这样的: while read line do code=`echo ${line} | awk '{print $1}'` awk -f ${supscript}/rearran
所以我正在构建这个脚本以从“垃圾”目录中获取一个文件并将其移动到主目录。我收到错误 mv:/home/user/Trash/和/home/user/Trash 是同一个文件。问题是我正在将文件移动到/
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
这是我的 bash 脚本,用于将 csv 文件复制到一个新文件,该文件的末尾添加了时间戳,然后复制到另一个服务器。 #!/bin/bash timestamp=`date +"%Y%m%d%H%M%S
如何移动( mv )具有空格和特殊字符的文件 - linux 命令 file.txt 包含以下内容。 04 安全@test.pdf 05 安全@test.pdf 我的命令如下: cat $DIR/fi
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
我想将所有匹配简单模式的文件移动到一个特定的文件夹中,但我真的不知道该怎么做;这是我试过的: mv *.o obj/*.o 别笑我,我对 linux 不是很得心应手。 p.s 我不知道它是否相关,但
当调用 git mv file1 file2 时,它是在内部记录移动(用于日志中的历史跟踪)还是与调用 mv file1 file2 完全相同,git rm file1 和 git add file2
当我运行 git-mv file1 file2 时,我将文件从 file1 移动到 file2,正如我所期望的那样。不过,有时我的 git status 会给出“奇怪”的输出。 当我运行 git-mv
我是一名优秀的程序员,十分优秀!