I'm trying to compile the following code but it won't work.
the compiler always tells me:
michael@michael :~/forum$ g++ *.cpp
ClassB.cpp: In member function `virtual void ClassB::abstrac tMethod(int) const
':
ClassB.cpp:6: error: passing `const ClassB' as `this' argument of `void
ClassA::setAttr ibute(int)' discards qualifiers
michael@michael :~/forum$
I've tried to compile the same code with Borland C++ BuilderX and it works.
this is the code I'm trying to compile:
//file ClassA.h
//file ClassB.h
//file ClassA.cpp
//file ClassB.cpp
the compiler always tells me:
michael@michael :~/forum$ g++ *.cpp
ClassB.cpp: In member function `virtual void ClassB::abstrac tMethod(int) const
':
ClassB.cpp:6: error: passing `const ClassB' as `this' argument of `void
ClassA::setAttr ibute(int)' discards qualifiers
michael@michael :~/forum$
I've tried to compile the same code with Borland C++ BuilderX and it works.
this is the code I'm trying to compile:
//file ClassA.h
Code:
#ifndef CLASSA_H #define CLASSA_H class ClassA{ private: int attribute; public: ClassA(int attribute); void setAttribute(int attribute); virtual void abstractMethod(int attribute)const=0; }; #endif
Code:
#ifndef CLASSB_H #define CLASSB_H #include "ClassA.h" class ClassB : public ClassA{ private: public: ClassB(int attribute); void abstractMethod(int attribute) const; }; #endif
Code:
#include "ClassA.h" ClassA::ClassA(int attribute){ this->attribute = attribute; }
Code:
#include "ClassB.h" ClassB::ClassB(int attribute): ClassA(attribute){} void ClassB::abstractMethod(int attribute) const{ setAttribute(attribute); }
Comment