Answers for "constructor in struct c++"

C++
7

constructor c++ struct

struct Rectangle {
    int width;  // member variable
    int height; // member variable

    // C++ constructors
    Rectangle()
    {
        width = 1;
        height = 1;
    }

    Rectangle( int width_  )
    {
        width = width_;
        height = width_ ;
    }

    Rectangle( int width_ , int height_ )
    {
        width = width_;
        height = height_;
    }
    // ...
};
Posted by: Guest on November-10-2020
1

how to create a struct in c++

struct product {
  int weight;
  double price;
} ;

product apple;
product banana, melon;
Posted by: Guest on August-20-2021

Browse Popular Code Answers by Language