I have a class with a public static member function. It seems that I can't define that function in a cpp file (with a very vague error) but I can compile fine when I define the function in a header. How can this be?
cmdlineparser.h
#ifndef __CMD_LINE_PARSER_H__
#define __CMD_LINE_PARSER_H__
//#include <getopt.h>
//#include "cmdlineargs.h"
class CmdLineParser
{
private:
//CmdLineParser() {}
//static void printCmdLineHelp();
public:
//static CmdLineArgs parse(int argc, char** argv);
static int parse();
};
#endif
cmdlineparser.cpp
#include "cmdlineparser.h"
int CmdLineParser::parse()
{
return 0;
}
main.cpp
#include "cmdlineparser.h"
int main(int argc, char** argv)
{
// Parse the command line arguments.
//int cmdLineArgs = CmdLineParser::parse(argc, argv);
int cmdLineArgs = CmdLineParser::parse();
return 0;
}
Error: undefined reference to CmdLineParser::parse()
It compiles when I put the definition in the header:
static int parse(){return 0;}
Any ideas?