[Solved] C++ object(int) [closed]


You want to overload << operator. For instance:

ostream& operator<<(ostream& os, const Date& dt)  
{  
    os << dt.mo << "https://stackoverflow.com/" << dt.da << "https://stackoverflow.com/" << dt.yr;  
    return os;  
} 

If a() isn’t constructor, but only a () operator overloaded which I assumed changes the a field of the class A to the parameter provided inside () your code could look something like this:

 class A{
      public:
      int a;
      A(int a){
          this->a = a;
      }
      A(){}

      friend ostream& operator<<(ostream& os, const A& dt);

      A operator()(int n){ //changes the current a to n
      this->a = n;
      return *this;
      }

      ostream& operator<<(ostream& os, const A& objectA){  
      os << objectA.a<<endl;
      return os;  
      } 

    int main()
    {
        A a(1500);
        cout<<a(1200);

        return 0;
    }

5

solved C++ object(int) [closed]