Hi, i got a destructor for a class Base1.
my syntax/format is wrong. can some-one correct it for me?
Thanks,Code:Base1::virtual ~Base1() {
cout << "Destroy Base" << endl;
}
Printable View
Hi, i got a destructor for a class Base1.
my syntax/format is wrong. can some-one correct it for me?
Thanks,Code:Base1::virtual ~Base1() {
cout << "Destroy Base" << endl;
}
All your qualifiers (eg: static, virtual, inline, etc) belong on the far left. Or, put another way, just as you declared it within the class with Base:: appended to the function name.
i.e.
Code:virtual Base1::~Base1()
{
std::cout << "destroy all yer base" << std::endl;
}
hi, did this declaration for my virtual desctructor.it continues to give me this error:virtual outside class declaration using dev c++ compiler
Code:#include <iostream>
using namespace std;
class Base1
{
private:
int baseValue;
public:
Base1(int y):baseValue(y){}
virtual ~Base1();
};
virtual Base1::~Base1()
{
std::cout << "destroy all yer base" << std::endl;
}
int main()
{
}
Not quite. The virtual keyword can only be used in the class declaration, not in that type of definition. Compiling this on Comeau gives me:
Code:"ComeauTest.c", line 8: error: invalid specifier outside a class declaration
virtual A::~A()
^
Code:class A
{
int m_A;
public:
virtual ~A();
};
virtual A::~A() // Remove the virtual keyword here.
{
m_A = 5;
}
int main()
{
A a;
return 0;
}
Geez, what the hell was I thinking? I really need a vacation. :D
Whoops. I'll use Sebastiani's excuse.