Prototype pour XXX::XXX ne correspond pas tout dans la classe XXX

J'ai écrit ce code simple:

principal.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;
}

Mais il ne compile pas. G++ erreur:

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

J'utilise G++ 4.8 (et CB 13.12 IDE).

  • Toutes les fonctions de membre que vous finirez par définir, y compris les constructeurs, doivent être déclarés en tant que membres de la classe.
InformationsquelleAutor Smarty77 | 2014-10-04