I've searched some but only found subjects based on C and not C++, here
So I was wondering whether there is a way to remove the main function using some weird function or something to shorten one's code
I've searched some but only found subjects based on C and not C++, here
So I was wondering whether there is a way to remove the main function using some weird function or something to shorten one's code
There are two ways.
The first is to build a library instead of an application. You can't run it, but it will build your code to a library that can be linked by other applications. In g++, for instance, you do this with:
g++ -c my_file.cc -o my_file.o
g++ -shared -o libmy_file.so my_file.o
The other way is to modify your linker script so that it uses an entry point other than main. It's not possible to do this in a way that conforms with the C++ standard, but most linkers will give you a way of doing it. See here for how to do it with the GNU linker, for instance.