I need to get rid of this warning. As far as I understand, it appears because DerivedClass is not considered as Plain Old Data. I read cppreference about POD and Standard Layout Type but I still do not understand why DerivedClass is not a POD. If I put members of BaseClass into DerivedClass and do not use inheritance - then everything is OK. I use C++11
Here is an example:
#include <iostream>
using namespace std;
class BaseClass
{
public:
int a;
};
class DerivedClass : public BaseClass
{
public:
int b;
};
int main(int argc, char *argv[])
{
// warning: offset of on non-standard-layout type 'DerivedClass'
int offset = offsetof(DerivedClass, b);
cout << offset;
}
I appreciate any help.
Aucun commentaire:
Enregistrer un commentaire