[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 395
  • Last Modified:

COM/DCOM

Hi experts,
           
                        what is the use of ATL_NO_VTABLE macro what it actually does. Is it disable the vtable of the base classes or the current class.

Regards,
Vimal.
0
vimalalex
Asked:
vimalalex
1 Solution
 
Todd GerbertIT ConsultantCommented:
According to MSDN (http://msdn.microsoft.com/en-us/library/w4baz6ss(v=VS.80).aspx), ATL_NO_VTABLE expands to declspec(novtable), which causes the linker to eliminate the vtable (and all the functions it points to), and should only ever be applied to an abstract base class.

It disables the vtable of the class to which the modifier is applied, but you should not apply it to your most-derived (or any creatable) class.
0
 
vimalalexAuthor Commented:
Hi tgerbert,

                       By eliminating vtable so we cant use function overridding right if we have normal virtual function in base class.What is the necessary for eliminating vtable of base class.

regards,
vimal.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Deepu AbrahamR & D Engineering ManagerCommented:
Hi Vimal,

No, I guess this is only meant for the specific class. See the example below:

Animal* animalObj = new Animal();
animalObj->eat();//-------> this will fail

And MSFT clearly says that "Using declspec(novtable)in a class declaration prevents the vtable pointer from being initialized in the class constructor and destructor. When you build your project, the linker eliminates the vtable and all functions to which the vtable points. "

This also explains it pretty neatly
http://www.codeproject.com/Messages/2380416/Re-ATL_NO_VTABLE-means.aspx
class __declspec(novtable) Animal {
    public:
         virtual void eat() const { 
            std::cout << "I eat like a generic Animal." << std::endl; 
        }
        virtual ~Animal() { 
        }
};
 
class Wolf : public Animal {
    public:
        void eat() const { 
            std::cout << "I eat like a wolf!" << std::endl; 
        }
        virtual ~Wolf() { 
        }
};


	//Animal* animalObj = new Animal(); 
	//animalObj->eat();//-------> this will fail
	
	Animal* animalObj = new Wolf();
	animalObj->eat();//-------> this will pass

Open in new window

0
 
vimalalexAuthor Commented:
Hi DeepuAbrahamK,

                       Thanks for your excellent reply.
Regards,
Vimal.
0
 
Todd GerbertIT ConsultantCommented:
MSDN also says "You must use ATL_NO_VTABLE, and consequently declspec(novtable), with only base classes that are not directly creatable", so you shouldn't apply it to Animal in the above example because Animal doesn't contain any pure virtual functions (i.e. it can be directly created).

The point is that since you can't create an abstract base class anyway, there's no need for it to have a vtable so it can be removed to reduce code size.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now