xFactorSchool.com(Beta)
How to Do Examples
Python Examples
HTML Examples
Code Examples
C Code Examples
C++ Code Examples
C# Code Examples
Java Code Examples
Python Code Examples
HTML Code Examples
CSS Code Examples
JavaScript Code Examples
Online Editor
C Code Editor
C++ Code Editor
C# Code Editor
Java Code Editor
Python Code Editor
HTML Code Editor
CSS Code Editor
JavaScript Code Editor
Practice how to create a class constructor with parameters in C++
C++ Online Editor
Execute Code
More C++ Sample Code
#include <iostream> #include <string> using namespace std; // use std namespace to avoid std:: before cout // This is a class class Person { public: string Name; int Age; // This is the class constructor Person(const string& name, int age) : Name(name), Age(age) {} }; int main() { // Parameter values are passed at the time of class instantiation (object declaration) Person personObj("John", 25); cout << personObj.Name << " is " << personObj.Age << " years old." << endl; return 0; }