Search code examples
c++qthread

ISO C++ forbids declaration of ‘setInputNombre’ with no type


This is my class

class PrimeThread : public QThread
{

private:
    long inputNombre;
    virtual void run() Q_DECL_OVERRIDE
    {
        ifstream primeFile("premier.txt", std::ios::in);
        long primeLigne;

        primeFile.close();
        primeFile.open("premier.txt", std::ifstream::in);
        cout << inputNombre << ": ";
        while (primeFile >> primeLigne)
        {
            while (inputNombre % primeLigne == 0 && inputNombre > 1)
            {
                cout << " " << primeLigne;
                inputNombre /= primeLigne;
            }
        }
        cout << endl;
        return;
    }

public:
    
    // PrimeThread(long inputNombre): QThread(), inptNb(inputNombre){};
    PrimeThread(){};
    setInputNombre(long inputnb) {
        inputNombre = inputnb;
    }
};

and this is the error **

main.cpp:38:32: error: ISO C++ forbids declaration of ‘setInputNombre’ with no type [-fpermissive] setInputNombre(long inputnb) {

**


Solution

  • Your setInputNombre does not have a type. What should it return? If you don't care, void is the answer:

     void setInputNombre(long inputnb) {
       // ...
     }