I know that vectors are guaranteed to have the same underlying memory layout as arrays. So for POD (plain-old-data) type like int
, vector<int> a
can be used as SomeCFun(&a[0], a.size())
when a
is non-empty. I'd like to know that when the element type is (complex) Class type, does the trick still work safely?
是的,对于任何类型T
,都保证为真。
Yes, it'll work. An alternative is SomeCFun(a.data(), a.size())
- but whatever you prefer.
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.