我想在C/C++中实现类似这样的概念。
一种可能的翻译是:“以某种方式能够拥有”。
我想把它解决为 (只复制相同的部分,扩展部分不变)
但对我来说有点丑。有没有更清晰的解决方案?可能是扩展一个结构或类似的东西吗?
struct first{
int a,b,c;
}my1;
struct second{
int a,b,c;
int extended;
}my2;
一种可能的翻译是:“以某种方式能够拥有”。
my2=my1;
我想把它解决为 (只复制相同的部分,扩展部分不变)
struct second{
first first_;
int extended;
}my2;
and have
my2.first_ = my1;
但对我来说有点丑。有没有更清晰的解决方案?可能是扩展一个结构或类似的东西吗?
memcpy
函数memcpy(&second, &first, sizeof(first));
。 - user1551592