I have quite a few source files in nested subfolders for a project. I have 4 different classes that I am attempting to replace, and want to locate every place in the source they are allocated (heap + stack).
Unfortunately, due to a poor include structure, Visual Studio’s “search entire solution” feature cannot be trusted, so I have resorted to a manual search within the source files.
What I believe is sufficient:
"new CLASS1(" with any combination of spaces between the three tokens there for heap and
"^CLASS2" where I’m trying to say the Class name starts at the beginning of the line (excluding spaces) for stack allocation.
For stack allocation, [^a-zA-Z] CLASS3 [a-zA-Z]+ was attempted, but I’m not fluent in regex so wanted to run this by SO. For heap, just that string above was tried, but I know that a simple extra spacing would break that pattern so I know it is incorrect.
Can anyone come up with a better matcher or even an entirely better way to go about the problem?
Thank you,
AK
Make the constructors private and you’ll get an error message for every attempt to create the object.
Make a private new() operator to do the same trick with heap allocations.
Edit: watch out for the code INSIDE the class implementation (including static methods) creating instances of itself. Calling a private constructor from such context is valid and won’t trigger an error. Also watch out for friend classes/functions.