Reputation: 1348
I have written this simple code:
main.h
#ifndef MAIN_H
#define MAIN_H
#include <stdio.h>
#include <iostream>
#include <vector>
#include <stdlib.h>
class Parameters
{
private:
std::string _hostname, _channel, _syslogs;
int _port;
std::vector<std::string> _list;
public:
std::string getHost() {return _hostname;}
std::string getChan() {return _channel;}
std::string getSys() {return _syslogs;}
std::vector<std::string> getList() {return _list;}
int getPort() {return _port;}
};
#endif // MAIN_H header guard
main.cpp
#include "main.h"
using namespace std;
Parameters::Parameters (int argc, char** argv){
if (argc<2 || argc>4){
fprintf(stderr,"ERROR: Invalid count of parameters\n");
exit(EXIT_FAILURE);
}
}
int main(int argc, char**argv)
{
Parameters parameters(argc,argv);
return 0;
}
But it won't compile. G++ error:
g++ -Wall -fexceptions -g -Wextra -Wall -c
/home/pathtoproject/main.cpp -o obj/Debug/main.o
/home/pathtoproject/main.cpp:13:1: error: prototype for
‘Parameters::Parameters(int, char**)’ does not match any in class
‘Parameters’
I am using G++ 4.8 (and CB 13.12 IDE).
Upvotes: 0
Views: 12767
Reputation: 5844
You have to add a declaration of the constructor into Parameters
:
class Parameters
{
private:
// ...
public:
// ...
Parameters(int argc, char** argv);
};
Otherwise, the compiler does not know that the constructor exists in other translation units where only the header is included. Your constructor must be declared public
section, so that it can be called in main
.
Upvotes: 1
Reputation: 726619
You are attempting to supply an implementation of a constructor that you have not declared as part of the class declaration.
You need to add this line to the public:
section of your class:
Parameters (int argc, char** argv);
This is the missing prototype about which the compiler is complaining. Adding this prototype will declare in the main.h
the constructor that you are defining in your main.cpp
.
Upvotes: 1