Constructor (object-oriented programming): Difference between revisions

Content deleted Content added
C++Bro123 (talk | contribs)
m C++: Improve C++ example
C++Bro123 (talk | contribs)
m Improve C++ examples
Line 15:
 
<source lang="cpp">
class Example {
public:
{
int x, yExample();
Example(int a, int b); // parameterisedParameterized constructor.
public:
 
Example();
private:
Example(int a, int b); // parameterised constructor
int x_;
int y_;
};
 
Example :: Example() = default;
{
 
Example :: Example(int ax, int by) : x_(x), y_(y) {}
{
x = a;
y = b;
}
</source>
 
<source lang="cpp">
Example e = Example(0, 50); // Explicit call.
Example ee2(0, 50); // Implicit call.
 
Example e(0, 50); // Implicit call
</source>
 
Line 45 ⟶ 41:
#include <iostream>
 
class studentStudent {
public:
Student(int a = 0, int a,b = 0); // Default constructor.
student(a=0,b=0) //default constructor
};
 
int main()a;
y =int b;
{
};
 
}
</source>