I came across the following error like below during my project. This error is reproduced with some dummy code for better understanding.
main.cpp:15:7: error: ‘class NameB’ has pointer data members [-Werror=effc++]
class NameB {
^
main.cpp:15:7: error: but does not override ‘NameB(const NameB&)’ [-Werror=effc++]
main.cpp:15:7: error: or ‘operator=(const NameB&)’ [-Werror=effc++]
I got the error when I build the following code using the command g++ main.cpp -Weffc++ -Werror
The code is
#include <iostream>
using namespace std;
class NameA {
private:
int m_item;
int m_dist;
public:
NameA(int a, int b): m_item(a), m_dist(b) {}
// NameA(const NameA& namea);
};
class NameB {
private:
NameA* m_namea;
int m_int;
public:
NameB():m_namea(NULL), m_int() {}
~NameB();
};
int main(int argc, char *argv[]) {
NameB *nb = new NameB();
if(nb) {
// suppress unused warning
}
}
If I remove the destructor from the class NameB
, the error has vanished. So could anyone please help me to get a clarification on this?