int main(void)和int main(int argc,char * argv) [英] int main(void) and int main(int argc , char *argv)

查看:66
本文介绍了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.


这篇关于int main(void)和int main(int argc,char * argv)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆