int main(void)和int main(int argc,char * argv)
问题描述:
我有一个程序,其中包含一个名为main.cpp的文件.这包括int(int argc,char * argv)我也有一个带有以下代码的头文件.问题是我不能使用int main(void),因为我已经在使用int main(int argc,char * argv)并且它们不能一起使用.我的问题是,我可以使用以下代码进行其他操作,从而不必使用int main(void).谢谢.
I have a program that has a file called main.cpp. This includes int(int argc, char *argv) I also have a header file with the code below. The problem is I can''t use int main(void) since I am already using an int main(int argc, char *argv) and they can''t be used together. My question is there something else that I can do with the code below so that I don''t have to use int main(void). Thank You.
#include <iostream>
#include <string>
#include <map>
using namespace std;
class Content {
public:
static Content* getContent(const string& type);
static void printCurrentTypes();
private:
static map<string,content*> types;
string type;
Content(const string& t) : type( t ) {}
};
map<string,content*> Content::types;
void Content::printCurrentTypes() {
if (!types.empty()) {
cout << "Number of instances made = " << types.size() << endl;
for (map<string,content*>::iterator iter = types.begin(); iter != types.end(); ++iter) {
cout << (*iter).first << endl;
}
cout << endl;
}
}
int main(void) {
Content::getContent("text/plain");
Content::printCurrentTypes();
Content::getContent("image/gif");
Content::printCurrentTypes();
Content::getContent("image/jpg");
Content::printCurrentTypes();
return 0;
}
答
将函数(您不想在启动时运行的函数)重命名为其他函数.
Rename the function (the one you do not want to run at startup) to something else.