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; }
This is a discussion on virtual destructor SYNTAX within the C++ Programming forums, part of the General Programming Boards category; Hi, i got a destructor for a class Base1. my syntax/format is wrong. can some-one correct it for me? Code: ...
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.
Code:int main(void){srand(time(0));for(double l=rand(),l0=0,l00=0;;l0+=0.1){for(double l000=0;l000 <1;l000+=.001,l+=((double)rand()/RAND_MAX)/0x64,l00+=((sin(l*0x8*atan(l0)*l000-(l0*0x8*atan (l)))*0.5)+0.5)){l00-=floor(l00);for(size_t l0000=0,l00000=(size_t)(0x50*(l00));l0000<l00000;++l0000 )putchar(0x20);putchar(0x61+(int)((double)rand()/RAND_MAX*0x1a));putchar('\n');}}return 0;}
i.e.
Code:virtual Base1::~Base1() { std::cout << "destroy all yer base" << std::endl; }
"If you tell the truth, you don't have to remember anything"
-Mark Twain
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; }
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010
Geez, what the hell was I thinking? I really need a vacation.![]()
Code:int main(void){srand(time(0));for(double l=rand(),l0=0,l00=0;;l0+=0.1){for(double l000=0;l000 <1;l000+=.001,l+=((double)rand()/RAND_MAX)/0x64,l00+=((sin(l*0x8*atan(l0)*l000-(l0*0x8*atan (l)))*0.5)+0.5)){l00-=floor(l00);for(size_t l0000=0,l00000=(size_t)(0x50*(l00));l0000<l00000;++l0000 )putchar(0x20);putchar(0x61+(int)((double)rand()/RAND_MAX*0x1a));putchar('\n');}}return 0;}
Whoops. I'll use Sebastiani's excuse.
"If you tell the truth, you don't have to remember anything"
-Mark Twain