Raised This Month: $ Target: $400
 0% 

Declare one hook in multiple cpp files


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
RomanPort
New Member
Join Date: Oct 2021
Old 12-31-2021 , 03:16   Re: Declare one hook in multiple cpp files
Reply With Quote #2

Hello! I just encountered the same problem and searched on this board for help. Surprisingly, this is the only mention I could find. I was stumped on this for a while, but just found the solution: typedefs.

Like you, I had the same hook declared in two different files and I was also getting errors about objects already existing. The reason why is that the SH_DECL_HOOK macro actually declares some variables that you can't see, and there are two with identical names created when you have two of those definitions. Since the name of these variables is derived from the interface name and function, if we can change the name, it'll work fine.

That's where typedefs come in. Typedefs are basically just an alias for a type name. If you set up an alias for the interface in one of the two files with a different name, you can declare the hooks using that new name instead and it won't conflict. It doesn't matter what your alias is as long as it's different from the old name.

At the top of one of your two files, add this line, replacing the two parts of it:

Code:
typedef <EXISTING TYPE NAME> <YOUR NEW TYPE NAME>;
Then, in the rest of just that file, replace any names of the original type (IServerEntity in your case) with your new alias name in any hook-related macros. From there it should compile fine.

tl;dr;

Add this line to the top of ONE of the two files: typedef IServerEntity IServerEntityFileOne;
Then, replace "IServerEntity" with "IServerEntityFileOne" everywhere else hook-related in that one file.
RomanPort is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:53.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode