简体   繁体   中英

Can I add main function in C++ header file?

Hi guys I have a vehicule.h header file like this

#include <iostream>
using namespace std;

class Vehicule{
    private:
    string type;
    //etc...
};
//can this function be there or do i need to add it on .cpp file?
int main(){
return 0;
}

Technically yes, you can. However, if you do put a non-inline function definition such as main into a header, then you may only include the header into one translation unit. This makes the header rather pointless. In conclusion, don't do it because it isn't useful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM