Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Ctor takes non-const reference but pass in a const array
//Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x64 #include <iostream> struct A { uint32_t m_a; }; struct B { template<typename Target, size_t size> constexpr B(Target(&target)[size]) : sizeTargetList{ size }, pTargetList{ target } { } uint32_t sizeTargetList; A* pTargetList; }; int main() { const A arrayOfA[] = {1, 2, 3, 4}; B b(arrayOfA); // Print size of the list std::cout << b.sizeTargetList << "\n\n"; // Print each element for (size_t i = 0; i < b.sizeTargetList; ++i) { std::cout << b.pTargetList[i].m_a << "\n"; } }
run
|
edit
|
history
|
help
0
infix to postfix v 3.0
std::function ambiguity vc++
Triangle N5
Unicode_wcout
Initializing member array of structs
operator new / delete
sharedptr emptiness
#32
Program_2
C++ exception