c++ - Call destructor from empty define? -


suppose following header file:

#ifndef test_header #define test_header   class myfoo {     public:     myfoo(unsigned long *ulbaz):     baz(ulbaz)     {       *baz++;     }     ~myfoo()     {       *baz--;     }     private:         unsigned long *baz;     };  #define define_a( ) myfoo bar( a); #define define_b( b )   #endif  // test_header 

code-example:

// code.cpp  #include "test.h" unsigned long mylong = 0l;   int main() {     define_a( &mylong);     define_b( &mylong); } 

as can see, define_b empty. don't understand: everytime define_b called, destructor myfoo, can see within callstack - how can be? far know empty define expands ;.

edit: code works.

i'm assuming running following main:

int main (int argc, char const* argv[]) {     unsigned long mylong = 0l;     define_a( &mylong);     define_b( &mylong);     return 0; } 

the line define_b( b ) expands nothing, see destructor of class myfoo because when end of scope reached, objects has been created inside them, deleted calling destructors.


Comments

Popular posts from this blog

design - Custom Styling Qt Quick Controls -

Unable to remove the www from url on https using .htaccess -