dimanche 12 septembre 2021

call to non-static member function without an object argument when call getter function

I have one struct :

struct Status
{
    std::string Available;
    std::string Connected;
    std::string DisConnected;
};

I create one object from this struct :

class Test
{
 public:
   Test();

   const Status &status() const;
   void setStatus(const Status &newStatus);

private:
    Status _status ;
};

and when I call getter function status like this :

  std::cout << "" << status();

I get this error :

illegal call of non-static member function

I don't know what should I do.

I try this way that set static status function but again I have this error:

   static const Status &status() ;

and in cpp:

const Status &Test::status()
{
    return _status;
}

invalid use of member '_status' in static member function

Aucun commentaire:

Enregistrer un commentaire