void f(int count, ...){
//whatever
}
struct somestruct{
size_t a, b, c;
};
int main() {
somestruct s;
f(1, s); //what is actually passed?
}
Is the entire struct
copied and passed on the stack? If so are copy constructors called? Is the pointer passed? Is this safe?
是的,如果您传递左值,则将完成左值到右值的转换,这意味着调用复制构造函数将对象复制到新副本中并将其作为参数传递。
void f(...)
is using bit-wised copy. No default constructor or copy constructor will be generated for your somestruct
as it only has C++ build-in types.
Is this safe?
Yes, this is perfectly safe.
I'll refer you to 'Inside C++ Object Model' chapter 2 The Semantics of Constructors
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.