Click here to Skip to main content
15,997,284 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.

C++
#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;
}
Posted
Updated 6-Sep-11 13:09pm
v2

1 solution

Rename the function (the one you do not want to run at startup) to something else.
 
Share this answer
 
Comments
Member 7766180 6-Sep-11 19:21pm    
The one above is the one that I don't want to run on startup. How do I do that?
Member 7766180 6-Sep-11 20:49pm    
I did this...
int red(void) {
Content::getContent("text/plain");
Content::printCurrentTypes();

Content::getContent("image/gif");
Content::printCurrentTypes();

Content::getContent("image/jpg");
Content::printCurrentTypes();

return 0;
}

Now I'm getting "LNK 2019 unresolved external symbol" and LNK 1120 unresolved externals.
Philippe Mori 6-Sep-11 21:32pm    
What are the unresolved symbols?
Member 7766180 6-Sep-11 21:48pm    
static Content* getContent(const string& type);
Philippe Mori 6-Sep-11 22:17pm    
It is because the function is not defined anywhere (where is the function body). Since you have implemented the other function (Content::printCurrentTypes), you should also implement this one (Content::getContent).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900