Is there anyway if we can replace main method from c++, or can we override or overload main method??? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Is there anyway if we can replace main method from c++, or can we override or overload main method???

this question is about c++ programming as we always run c++ program the compiler invokes main method first of all. My question is why we can't replace it with anyother method?

26th Jan 2018, 5:13 AM
Subhan Mangi
Subhan Mangi - avatar
3 Answers
+ 3
Yes, you can. But to do this you have to change in Visual Studio linker settings!
26th Jan 2018, 5:47 AM
Paweł Karaś
Paweł Karaś - avatar
+ 2
1) Why would you want to? 2) main is not a method.
26th Jan 2018, 7:00 AM
Vlad Serbu
Vlad Serbu - avatar
+ 1
Thats how the language works. You cannot replace or override main, but you can do : #define start main int start() { // do stuff you would earlier do in main. } And obviously, you can use C++ to write a new language that does not require this 'main' function at all. Its your wish though, what you want to do. Also visit : https://stackoverflow.com/questions/7050925/is-it-possible-to-write-a-program-without-using-main-function https://stackoverflow.com/questions/5282151/can-we-overload-main-function-in-c
26th Jan 2018, 5:41 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar