Answers for "c++ class constructor"

C++
0

constructor in c++

class A{
 private:
  int val;
 public:
  A(int x){             //one argument constructor
   val=x;
  }
  A(){                    //zero argument constructor
  }
}
int main(){
 A a(3);     

 return 0;
}
Posted by: Guest on October-29-2021
0

formats of constructor in c++

Line::Line( double len): length(len) {
   cout << "Object is being created, length = " << len << endl;
}
Posted by: Guest on November-12-2020
0

constructor syntax in c++

struct S {
    int n;
    S(int); // constructor declaration
    S() : n(7) {} // constructor definition.
                  // ": n(7)" is the initializer list
                  // ": n(7) {}" is the function body
};
S::S(int x) : n{x} {} // constructor definition. ": n{x}" is the initializer list
int main()
{
    S s; // calls S::S()
    S s2(10); // calls S::S(int)
}
Posted by: Guest on August-17-2021
0

C++ constructor

class Book {public:    Book(const char*);    ~Book();    void display();private:    char* name;};
Posted by: Guest on June-20-2021

Browse Popular Code Answers by Language