mardi 24 avril 2018

no matching function for call to C++ constructor [duplicate]

This question already has an answer here:

#include "Generator.h"
#include <math.h>
#include <stdlib.h>
#include <time.h>

Generator::Generator(int inputbits):bits(inputbits)
{
    srand(time(NULL));
    bits=rand() % int(pow(2, inputbits));
}

Generator::~Generator()
{

}

int Generator::getBits()
{
    return bits;
}

.

#ifndef GENERATOR_H
#define GENERATOR_H


class Generator
{
    public:
        ~Generator();
        int getBits();
        static Generator* getInstance();
    private:
        Generator(int);
        int bits;
};

.

#endif // GENERATOR_H


#include "Generator.h"
#include "Proxy.h"

Proxy::Proxy(int inputbits):bits(inputbits)
{

}

Proxy::~Proxy()
{
    //dtor
}

.

#ifndef PROXY_H
#define PROXY_H
#include "Generator.h"

class Proxy: private Generator
{
    public:
        ~Proxy();

    private:
        Proxy(int);
        int bits;
};

#endif // GENERATORPROXY_H

These are my code. Error happens like this

||=== Build: Debug in FinalProject (compiler: GNU GCC Compiler) ===|
C:\Users\1\Desktop\2018 spring OOP\designpattern\FinalProject\Proxy.cpp||In constructor 'Proxy::Proxy(int)':|
C:\Users\1\Desktop\2018 spring OOP\designpattern\FinalProject\Proxy.cpp|4|error: no matching function for call to 'Generator::Generator()'|
C:\Users\1\Desktop\2018 spring OOP\designpattern\FinalProject\Generator.h|12|note: candidate: Generator::Generator(int)|
C:\Users\1\Desktop\2018 spring OOP\designpattern\FinalProject\Generator.h|12|note:   candidate expects 1 argument, 0 provided|
C:\Users\1\Desktop\2018 spring OOP\designpattern\FinalProject\Generator.h|5|note: candidate: Generator::Generator(const Generator&)|
C:\Users\1\Desktop\2018 spring OOP\designpattern\FinalProject\Generator.h|5|note:   candidate expects 1 argument, 0 provided|
||=== Build finished: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

Issues happens here : Proxy::Proxy(int inputbits):bits(inputbits) which is constructor of Proxy. I made some base class called Generator, and derived class which is private subclass of Generator and has private constructor. I cannot get why this error happens. Please enlighten me if you any idea. It would be apprieciated.

Aucun commentaire:

Enregistrer un commentaire