struct POD{ par1 a; par2 b; par3 c;};class FOOBAR{ POD m_POD;public: FOOBAR(POD* pPOD) { assert(pPOD); // validate parameter memcpy((void*)&m_POD,pPOD,sizeof(POD)); // Cast is evil! };};
Yes, I know the C-style cast is evil.
This saves stack bashing, but costs you a level of indirection within your class.
Alternatively, you can unwrap the passed pointer in the constructor, and not have the indirection:
class FOOBAR{ par1 m_a; par2 m_b; par3 m_c;public: FOOBAR(POD* pPOD) { assert(pPOD); m_a = pPOD->a; m_b = pPOD->b; m_c = pPOD->c; };};
This works well if you're creating a lot of instances with similar parameters, or parameters that don't change much - you simply tweak your single instance of the argument struct as you go along.