Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does order of method declarations in a class matter to the compiler?

Tags:

c++

I am using a third-party static library (.lib file) in a C++ project. The author of the static library added a method to a class for me and sent me an updated build of the library.

Unfortunately, he didn't send a new header file and communication with him is slow, so I may not get the new header soon. I know the method signature of the new method, so I could just add it to the header file.

My question is whether it matters where in the list of public methods I add the new declaration (top, bottom, middle...). My best guess is that it does and that the order in the header file determines the order in the compiled class. Can someone confirm or refute this?

like image 593
adv12 Avatar asked Jan 25 '16 14:01

adv12


1 Answers

My question is whether it matters where in the list of public methods I add the new declaration

AFAIK, it does not matter if the member function is regular function but it matters if it is a virtual member function. The virtual member functions in the virtual table are in a certain order. If the library has them in a different order than your .h file, you'll most likely end up calling the wrong function.

Related: Force the order of functions in the virtual method table?

like image 194
R Sahu Avatar answered Nov 15 '22 07:11

R Sahu