{"id":6037,"date":"2021-03-19T11:20:11","date_gmt":"2021-03-19T11:20:11","guid":{"rendered":"https:\/\/wordpress-theme.spider-themes.net\/docy\/docs\/docly-documentation\/layouts\/another-layout\/"},"modified":"2024-04-07T01:19:41","modified_gmt":"2024-04-07T01:19:41","slug":"constructors","status":"publish","type":"docs","link":"https:\/\/adelnasim.com\/ar\/docs\/courses\/oop\/constructors\/","title":{"rendered":"\u0623\u062f\u0627\u0629 \u0627\u0644\u0628\u0646\u0627\u0621 Constructors"},"content":{"rendered":"<p><strong>\u0645\u0627 \u0647\u0648 \u0627\u0644\u0640Constructor\u061f<\/strong><br \/>\n\u0641\u064a \u0644\u063a\u0629 C++\u060c \u0627\u0644\u0640constructor \u0647\u0648 \u062f\u0627\u0644\u0629 \u0639\u0636\u0648 \u062e\u0627\u0635\u0629 \u062f\u0627\u062e\u0644 \u0641\u0626\u0629 class \u064a\u062a\u0645 \u0627\u0633\u062a\u062f\u0639\u0627\u0624\u0647\u0627 \u062a\u0644\u0642\u0627\u0626\u064a\u064b\u0627 \u0639\u0646\u062f \u0625\u0646\u0634\u0627\u0621 \u0643\u0627\u0626\u0646 object \u0645\u0646 \u062a\u0644\u0643 \u0627\u0644\u0641\u0626\u0629. \u0648\u0627\u0644\u063a\u0631\u0636 \u0627\u0644\u0623\u0633\u0627\u0633\u064a \u0645\u0646\u0647 \u0647\u0648 \u062a\u0647\u064a\u0626\u0629 \u0623\u0639\u0636\u0627\u0621 \u0628\u064a\u0627\u0646\u0627\u062a \u0627\u0644\u0643\u0627\u0626\u0646 object \u0623\u0648 \u0625\u062c\u0631\u0627\u0621 \u0623\u064a \u0625\u0639\u062f\u0627\u062f \u0636\u0631\u0648\u0631\u064a \u0644\u0644\u0643\u0627\u0626\u0646. \u064a\u062a\u0623\u0643\u062f \u0627\u0644\u0645\u0646\u0634\u0626\u0648\u0646 \u0645\u0646 \u0623\u0646 \u0627\u0644\u0643\u0627\u0626\u0646 \u064a\u0628\u062f\u0623 \u0628\u062d\u0627\u0644\u0629 \u0635\u0627\u0644\u062d\u0629.<\/p>\n<ol>\n<li>\u0627\u0633\u0645 \u0627\u0644\u0640Constructor:<br \/>\n\u0627\u0644\u0640Constructors  \u0644\u062f\u064a\u0647\u0645 \u0646\u0641\u0633 \u0627\u0633\u0645 \u0627\u0644\u0640class \u0627\u0644\u0630\u064a \u064a\u0646\u062a\u0645\u0648\u0646 \u0625\u0644\u064a\u0647.<\/li>\n<li>\u0644\u0627 \u062a\u0648\u062c\u062f \u0642\u064a\u0645\u0629 \u0625\u0631\u062c\u0627\u0639:<br \/>\n\u0644\u0627 \u064a\u064f\u0631\u062c\u0639 \u0627\u0644\u0640Constructors \u0623\u064a \u0642\u064a\u0645\u0629\u060c \u0648\u0644\u0627 \u062d\u062a\u0649 void.<\/li>\n<li>\u0625\u0639\u0637\u0627\u0621 \u0642\u064a\u0645\u0629 \u0644\u0644\u0640object:<br \/>\n\u064a\u062a\u0645 \u0627\u0633\u062a\u062e\u062f\u0627\u0645 \u0627\u0644\u0640Constructors  \u0644\u0625\u0646\u0634\u0627\u0621 object \u062c\u062f\u064a\u062f \u0648\u0625\u0639\u062f\u0627\u062f\u0647.<\/li>\n<\/ol>\n<p><strong>\u0623\u0646\u0648\u0627\u0639 \u0627\u0644\u0640Constructors:<\/strong><\/p>\n<ol>\n<li>Default\/ Empty Constructor:<br \/>\n\u064a\u062a\u0645 \u0625\u0646\u0634\u0627\u0624\u0647 \u062a\u0644\u0642\u0627\u0626\u064a\u064b\u0627 \u0628\u0648\u0627\u0633\u0637\u0629 \u0627\u0644\u0645\u062a\u0631\u062c\u0645 compiler  \u0625\u0630\u0627 \u0644\u0645 \u064a\u062a\u0645 \u062a\u0639\u0631\u064a\u0641 \u0623\u064a constructor \u0628\u0634\u0643\u0644 \u0635\u0631\u064a\u062d.<br \/>\n\u0625\u0646\u0634\u0627\u0621 \u0623\u0639\u0636\u0627\u0621 \u0627\u0644\u0640object \u0628\u0625\u0633\u062a\u062e\u062f\u0627\u0645 \u0642\u064a\u0645 \u0625\u0641\u062a\u0631\u0627\u0636\u064a\u0629.<br \/>\n\u0628\u0646\u0627\u0621 \u0627\u0644\u062c\u0645\u0644\u0629: ClassName() { \/* Initialization code *\/ }<br \/>\n<strong>\u0645\u062b\u0627\u0644 1:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;iostream&gt;\r\n#include &lt;cstdlib&gt;\r\nusing namespace std;\r\nclass Triangle\r\n{\r\n    private:\r\n        int base;\r\n        int height;\r\n    public:\r\n        \/\/empty constructor, no arguments are required\r\n        Triangle()\r\n        {\r\n            cout &lt;&lt; \"first constructor\\n\";\r\n        }\r\n        void setBase_Height(int b, int h)\r\n        {\r\n            base = b;\r\n            height =h;\r\n        }\r\n        float area()\r\n        {\r\n            return 0.5*base*height;\r\n        }\r\n        void print()\r\n        {\r\n            cout &lt;&lt; \"base = \" &lt;&lt; base &lt;&lt; endl\r\n                 &lt;&lt; \"height = \" &lt;&lt; height &lt;&lt; endl\r\n                 &lt;&lt; \"area = \" &lt;&lt; area() &lt;&lt; endl;\r\n        }\r\n};\r\nint main()\r\n{\r\n    Triangle ob;\r\n    ob.setBase_Height(10, 5);\r\n    ob.print();\r\n\r\n    return 0;\r\n}<\/pre>\n<p>\u062a\u0645 \u062a\u0639\u0631\u064a\u0641 (empty constructor) (Triangle()). \u064a\u062a\u0645 \u0627\u0633\u062a\u062f\u0639\u0627\u0624\u0647 \u062a\u0644\u0642\u0627\u0626\u064a\u064b\u0627 \u0639\u0646\u062f \u0625\u0646\u0634\u0627\u0621 object \u0648\u0637\u0628\u0627\u0639\u0629 \"first constructor\".<\/li>\n<li>Parameterized Constructor:<br \/>\n\u064a\u0642\u0628\u0644 parameters \u0623\u062b\u0646\u0627\u0621 \u0625\u0646\u0634\u0627\u0621 \u0627\u0644\u0640object \u0644\u062a\u062e\u0635\u064a\u0635 \u0627\u0644\u062d\u0627\u0644\u0629 \u0627\u0644\u0623\u0648\u0644\u064a\u0629.<br \/>\n\u064a\u0648\u0641\u0631 \u0627\u0644\u0645\u0631\u0648\u0646\u0629 \u0644\u0644\u0640objects  \u0644\u0644\u0628\u062f\u0621 \u0628\u0642\u064a\u0645 \u0645\u062e\u062a\u0644\u0641\u0629.<br \/>\n\u0628\u0646\u0627\u0621 \u0627\u0644\u062c\u0645\u0644\u0629: ClassName(type param1, type param2, \u2026) { \/* Initialization code *\/ }<br \/>\n<strong>\u0645\u062b\u0627\u0644 2:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;iostream&gt;\r\n#include &lt;cstdlib&gt;\r\nusing namespace std;\r\nclass Triangle\r\n{\r\n    private:\r\n        int base;\r\n        int height;\r\n    public:\r\n        \/\/empty constructor, no arguments are required\r\n        Triangle()\r\n        {\r\n            cout &lt;&lt; \"first constructor\\n\";\r\n            base = 0;\r\n            height = 0;\r\n        }\r\n        \/\/parameterized constructor\r\n        Triangle(int b, int h)\r\n        {\r\n            base = b;\r\n            height = h;\r\n            cout &lt;&lt; \"parameterized constructor\\n\";\r\n        }\r\n        void setBase_Height(int b, int h)\r\n        {\r\n            base = b;\r\n            height = h;\r\n        }\r\n        float area()\r\n        {\r\n            return 0.5*base*height;\r\n        }\r\n        void print()\r\n        {\r\n            cout &lt;&lt; \"base = \" &lt;&lt; base &lt;&lt; endl\r\n                 &lt;&lt; \"height = \" &lt;&lt; height &lt;&lt; endl\r\n                 &lt;&lt; \"area = \" &lt;&lt; area() &lt;&lt; endl;\r\n        }\r\n};\r\nint main()\r\n{\r\n    Triangle ob(5, 10);\r\n    \/\/ob.setBase_Height(10, 5);\r\n    ob.print();\r\n\r\n    return 0;\r\n}\r\n<\/pre>\n<p>Parameterized Constructor:<\/p>\n<p>\u064a\u0642\u0628\u0644 (parameters) (int b \u0648int h) \u0644\u0644\u062a\u0647\u064a\u0626\u0629 \u0627\u0644\u0645\u062e\u0635\u0635\u0629.<br \/>\n\u064a\u0637\u0628\u0639 \u201cparameterized constructor\u201d \u0639\u0646\u062f\u0645\u0627 \u064a\u062a\u0645 \u0625\u0633\u062a\u062f\u0639\u0627\u0624\u0647.<br \/>\n\u064a\u062a\u0645 \u0627\u0633\u062a\u062e\u062f\u0627\u0645 The parameterized constructor \u0623\u062b\u0646\u0627\u0621 \u0625\u0646\u0634\u0627\u0621 \u0627\u0644\u0643\u0627\u0626\u0646 object\u060c \u0645\u0645\u0627 \u064a\u0648\u0641\u0631 \u0642\u064a\u0645\u064b\u0627 \u0623\u0648\u0644\u064a\u0629 \u0644\u0623\u0639\u0636\u0627\u0621 \u0627\u0644\u0642\u0627\u0639\u062f\u0629 \u0648\u0627\u0644\u0627\u0631\u062a\u0641\u0627\u0639.<\/li>\n<\/ol>\n<p><strong>\u0645\u062b\u0627\u0644 3:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;iostream&gt;\r\n#include &lt;cstdlib&gt;\r\nusing namespace std;\r\nclass student {\r\n    private:\r\n        char name[20];\r\n        int id;\r\n    public:\r\n        student()\r\n        {\r\n            strcpy_s(name, \"no name\");\r\n            id = 0;\r\n        }\r\n        student(char n[], int i)\r\n        {\r\n            cout &lt;&lt; \"parameterized constructor\\n\";\r\n            strcpy_s(name, n);\r\n            id = i;\r\n        }\r\n        student(char n[])\r\n        {\r\n            strcpy_s(name, n);\r\n        }\r\n        void print()\r\n        {\r\n            cout &lt;&lt; \"name = \" &lt;&lt; name &lt;&lt; endl;\r\n            cout &lt;&lt; \"id = \" &lt;&lt; id &lt;&lt; endl;\r\n        }\r\n};\r\nint main()\r\n{\r\n    student ob(\"Mohammed\", 1450902032);\r\n    ob.print();\r\n\r\n    return 0;\r\n}<\/pre>\n<p>\u064a\u062d\u062f\u062f \u0647\u0630\u0627 \u0627\u0644\u0631\u0645\u0632 \u0637\u0627\u0644\u0628\u064b\u0627 \u0641\u064a \u0627\u0644\u0641\u0635\u0644 \u064a\u0645\u062b\u0644 \u0637\u0627\u0644\u0628\u064b\u0627 \u0644\u0647 \u0627\u0633\u0645 \u0648\u0645\u0639\u0631\u0641 \u0645\u062a\u063a\u064a\u0631\u0627\u062a \u0627\u0644\u0623\u0639\u0636\u0627\u0621 \u0627\u0644\u062e\u0627\u0635\u0629. \u062a\u062a\u0636\u0645\u0646 \u0627\u0644\u0641\u0626\u0629 \u062b\u0644\u0627\u062b\u0629 (constrctors):  empty constructor,  parameterized constructor \u0628\u0627\u0644\u0627\u0633\u0645 \u0648\u0627\u0644\u0645\u0639\u0631\u0641\u060c \u0648parameterized constructor \u0628\u0627\u0644\u0627\u0633\u0645 \u0641\u0642\u0637. \u062f\u0639\u0648\u0646\u0627 \u0646\u062d\u0644\u0644 \u0627\u0644\u0643\u0648\u062f \u062e\u0637\u0648\u0629 \u0628\u062e\u0637\u0648\u0629:<\/p>\n<p>\u2013 \u062a\u0639\u0631\u064a\u0641 \u0627\u0644\u0640(Class): student<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class student {\r\nprivate:\r\n    char name[20];\r\n    int id;\r\n\r\npublic:\r\n    \/\/ Empty Constructor\r\n    student() {\r\n        strcpy_s(name, \"no name\");\r\n        id = 0;\r\n    }\r\n\r\n    \/\/ Parameterized Constructor (with name and id)\r\n    student(char n[], int i) {\r\n        cout &lt;&lt; \"parameterized constructor\\n\";\r\n        strcpy_s(name, n);\r\n        id = i;\r\n    }\r\n\r\n    \/\/ Parameterized Constructor (with name only)\r\n    student(char n[]) {\r\n        strcpy_s(name, n);\r\n    }\r\n\r\n    \/\/ Member Function to print student details\r\n    void print() {\r\n        cout &lt;&lt; \"name = \" &lt;&lt; name &lt;&lt; endl;\r\n        cout &lt;&lt; \"id = \" &lt;&lt; id &lt;&lt; endl;\r\n    }\r\n};\r\n<\/pre>\n<ul>\n<li>Empty Constructor:<br \/>\n\u062a\u0647\u064a\u0626\u0629 \u0627\u0644\u0627\u0633\u0645 \u0625\u0644\u0649 \"no name\" \u0648\u0627\u0644\u0645\u0639\u0631\u0641 \u0625\u0644\u0649 0.<\/li>\n<li>Parameterized Constructor (\u0628\u0627\u0644\u0625\u0633\u0645 \u0648\u0627\u0644\u0645\u0639\u0631\u0641):<br \/>\n\u064a\u0642\u0628\u0644 parameters (char n[] and int i).<br \/>\n\u064a\u0637\u0628\u0639 \u201cparameterized constructor\u201d \u0639\u0646\u062f\u0645\u0627 \u064a\u062a\u0645 \u0625\u0633\u062a\u062f\u0639\u0627\u0624\u0647.<br \/>\n\u064a\u0639\u064a\u0646 \u0627\u0644\u0627\u0633\u0645 \u0648\u0627\u0644\u0645\u0639\u0631\u0641 \u0628\u0646\u0627\u0621\u064b \u0639\u0644\u0649 \u0627\u0644\u0642\u064a\u0645 \u0627\u0644\u0645\u064f\u062f\u062e\u0644\u0629.<\/li>\n<li>Parameterized Constructor (\u0628\u0627\u0644\u0625\u0633\u0645 \u0641\u0642\u0637):<br \/>\n\u064a\u0642\u0628\u0644  parameter (char n[]).<br \/>\n\u062a\u0647\u064a\u0626\u0629 \u0633\u0645\u0629 \u0627\u0644\u0627\u0633\u0645 \u0641\u0642\u0637.<\/li>\n<li>\u0623\u0639\u0636\u0627\u0621 \u0627\u0644\u0640Function:<br \/>\nprint: \u064a\u0639\u0631\u0636 \u0627\u0633\u0645 \u0627\u0644\u0637\u0627\u0644\u0628 \u0648\u0647\u0648\u064a\u062a\u0647.<\/li>\n<\/ul>\n<p>\u0627\u0644\u062f\u0627\u0644\u0629 \u0627\u0644\u0631\u0626\u064a\u0633\u0629 main:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int main() {\r\n    \/\/ Object of class student created using the parameterized constructor with name and id\r\n    student ob(\"Mohammed\", 1450902032);\r\n\r\n    \/\/ Printing the details of the student\r\n    ob.print();\r\n\r\n    return 0;\r\n}\r\n<\/pre>\n<ul>\n<li>\u0625\u0646\u0634\u0627\u0621 \u0627\u0644\u0643\u0627\u0626\u0646 object:<br \/>\n\u064a\u062a\u0645 \u0625\u0646\u0634\u0627\u0621 \u0643\u0627\u0626\u0646 ob \u0645\u0646 \u0627\u0644\u0646\u0648\u0639 Student \u0628\u0627\u0633\u062a\u062e\u062f\u0627\u0645 \u0627\u0644\u0640parameterized constructor \u0628\u0643\u0644 \u0645\u0646 \u0627\u0644\u0627\u0633\u0645 \u0648\u0627\u0644\u0645\u0639\u0631\u0641.<\/li>\n<li>\u062a\u0641\u0627\u0635\u064a\u0644 \u0627\u0644\u0637\u0628\u0627\u0639\u0629:<br \/>\n\u064a\u062a\u0645 \u0627\u0633\u062a\u062f\u0639\u0627\u0621 \u062f\u0627\u0644\u0629 \u0639\u0636\u0648 \u0627\u0644\u0637\u0628\u0627\u0639\u0629 \u0644\u0639\u0631\u0636 \u062a\u0641\u0627\u0635\u064a\u0644 \u0627\u0644\u0637\u0627\u0644\u0628 \u0628\u0645\u0627 \u0641\u064a \u0630\u0644\u0643 \u0627\u0644\u0627\u0633\u0645 \u0648\u0627\u0644\u0645\u0639\u0631\u0641.<\/li>\n<\/ul>\n<p>\u0645\u062e\u0631\u062c\u0627\u062a \u0647\u0630\u0627 \u0627\u0644\u0628\u0631\u0646\u0627\u0645\u062c \u0633\u062a\u0643\u0648\u0646 \u0643\u0627\u0644\u062a\u0627\u0644\u064a:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">parameterized constructor\r\nname = Mohammed\r\nid = 1450902032\r\n<\/pre>\n<p>\u064a\u0648\u0636\u062d \u0647\u0630\u0627 \u0627\u0644\u0643\u0648\u062f \u0627\u0633\u062a\u062e\u062f\u0627\u0645 constructors \u0645\u062a\u0639\u062f\u062f\u0629 \u0641\u064a \u0641\u0626\u0629 C++. \u0627\u0639\u062a\u0645\u0627\u062f\u064b\u0627 \u0639\u0644\u0649 \u0627\u0644\u0640arguments \u0627\u0644\u0645\u062a\u0648\u0641\u0631\u0629 \u0623\u062b\u0646\u0627\u0621 \u0625\u0646\u0634\u0627\u0621 \u0627\u0644\u0643\u0627\u0626\u0646\u060c \u064a\u0645\u0643\u0646 \u0627\u0633\u062a\u062f\u0639\u0627\u0621 constructors \u0645\u062e\u062a\u0644\u0641\u0629 \u0644\u062a\u0647\u064a\u0626\u0629 \u0627\u0644\u0643\u0627\u0626\u0646 \u0648\u0641\u0642\u064b\u0627 \u0644\u0630\u0644\u0643.<\/p>\n<p>3. Copy Constructor:<\/p>\n<p><strong>\u0645\u062b\u0627\u0644 4:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;iostream&gt;\r\nusing namespace std;\r\nclass Copy {\r\n    private:\r\n        int a1, a2, a3, a4, a5, a6, a7, a8;\r\n    public:\r\n        Copy(int aa1, int aa2, int aa3, int aa4,\r\n            int aa5, int aa6, int aa7, int aa8)\r\n        {\r\n            a1 = aa1;\r\n            a2 = aa2;\r\n            a3 = aa3;\r\n            a4 = aa4;\r\n            a5 = aa5;\r\n            a6 = aa6;\r\n            a7 = aa7;\r\n            a8 = aa8;\r\n        }\r\n        Copy(const Copy &amp;a)\r\n        {\r\n            a1 = a.a1;\r\n            a2 = a.a2;\r\n            a3 = a.a3;\r\n            a4 = a.a4;\r\n            a5 = a.a5;\r\n            a6 = a.a6;\r\n            a7 = a.a7;\r\n            a8 = a.a8;\r\n        }\r\n        void print()\r\n        {\r\n            cout &lt;&lt; a1 &lt;&lt; \" \" &lt;&lt; a2 &lt;&lt; \" \" &lt;&lt; a3 &lt;&lt; \" \" &lt;&lt; a4 &lt;&lt; \" \"\r\n                 &lt;&lt; a5 &lt;&lt; \" \" &lt;&lt; a6 &lt;&lt; \" \" &lt;&lt; a7 &lt;&lt; \" \" &lt;&lt; a8 &lt;&lt; \" \" &lt;&lt; endl;\r\n        }\r\n};\r\nint main()\r\n{\r\n    Copy g(1, 2, 3, 4, 5, 6, 7, 8);\r\n    g.print();\r\n    Copy h(g);\r\n    h.print();\r\n\r\n    return 0;\r\n}\r\n<\/pre>\n<p>\u064a\u062d\u062f\u062f \u0647\u0630\u0627 \u0627\u0644\u0643\u0648\u062f \u0646\u0633\u062e\u0629 \u0641\u0626\u0629 \u0645\u0639 constructors \u0627\u062b\u0646\u064a\u0646 - \u0623\u062d\u062f\u0647\u0645\u0627 \u0644\u062a\u0647\u064a\u0626\u0629 \u0643\u0627\u0626\u0646 \u0628\u0642\u064a\u0645 \u0645\u062d\u062f\u062f\u0629 \u0648\u0627\u0644\u0622\u062e\u0631 \u0644\u0625\u062c\u0631\u0627\u0621 \u0646\u0633\u062e\u0629 \u0639\u0645\u064a\u0642\u0629 \u0645\u0646 \u0643\u0627\u0626\u0646 \u0645\u0648\u062c\u0648\u062f. \u062f\u0639\u0648\u0646\u0627 \u0646\u062d\u0644\u0644 \u0627\u0644\u0643\u0648\u062f:<\/p>\n<p>\u2013 \u062a\u0639\u0631\u064a\u0641 \u0627\u0644\u0640(Class): Copy<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class Copy {\r\nprivate:\r\n    int a1, a2, a3, a4, a5, a6, a7, a8;\r\n\r\npublic:\r\n    \/\/ Parameterized Constructor for Initialization\r\n    Copy(int aa1, int aa2, int aa3, int aa4,\r\n         int aa5, int aa6, int aa7, int aa8) {\r\n        a1 = aa1;\r\n        a2 = aa2;\r\n        a3 = aa3;\r\n        a4 = aa4;\r\n        a5 = aa5;\r\n        a6 = aa6;\r\n        a7 = aa7;\r\n        a8 = aa8;\r\n    }\r\n\r\n    \/\/ Copy Constructor for Deep Copy\r\n    Copy(const Copy &amp;a) {\r\n        a1 = a.a1;\r\n        a2 = a.a2;\r\n        a3 = a.a3;\r\n        a4 = a.a4;\r\n        a5 = a.a5;\r\n        a6 = a.a6;\r\n        a7 = a.a7;\r\n        a8 = a.a8;\r\n    }\r\n\r\n    \/\/ Member Function to Print Object Details\r\n    void print() {\r\n        cout &lt;&lt; a1 &lt;&lt; \" \" &lt;&lt; a2 &lt;&lt; \" \" &lt;&lt; a3 &lt;&lt; \" \" &lt;&lt; a4 &lt;&lt; \" \"\r\n             &lt;&lt; a5 &lt;&lt; \" \" &lt;&lt; a6 &lt;&lt; \" \" &lt;&lt; a7 &lt;&lt; \" \" &lt;&lt; a8 &lt;&lt; \" \" &lt;&lt; endl;\r\n    }\r\n};\r\n<\/pre>\n<ul>\n<li>Parameterized Constructor:<br \/>\n\u062a\u0647\u064a\u0626\u0629 \u0627\u0644\u0643\u0627\u0626\u0646 \u0628\u0642\u064a\u0645 \u0645\u062d\u062f\u062f\u0629 \u0645\u0642\u062f\u0645\u0629 \u0643\u0640arguments.<\/li>\n<li>Copy Constructor:<br \/>\n\u0625\u062c\u0631\u0627\u0621 \u0646\u0633\u062e\u0629 \u0639\u0645\u064a\u0642\u0629 \u0645\u0646 \u0643\u0627\u0626\u0646 \u0645\u0648\u062c\u0648\u062f (Copy &amp;a).<br \/>\n\u0646\u0633\u062e \u0643\u0644 \u0645\u062a\u063a\u064a\u0631 \u0639\u0636\u0648 \u0644\u0644\u0643\u0627\u0626\u0646 \u0627\u0644\u0645\u0635\u062f\u0631 \u0625\u0644\u0649 \u0627\u0644\u0643\u0627\u0626\u0646 \u0627\u0644\u062c\u062f\u064a\u062f.<\/li>\n<li>\u062f\u0627\u0644\u0629 Print:<br \/>\n\u064a\u0639\u0631\u0636 \u0642\u064a\u0645 \u0645\u062a\u063a\u064a\u0631\u0627\u062a \u0623\u0639\u0636\u0627\u0621 \u0627\u0644\u0643\u0627\u0626\u0646.<\/li>\n<\/ul>\n<p>\u0627\u0644\u062f\u0627\u0644\u0629 \u0627\u0644\u0631\u0626\u064a\u0633\u0629 main:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int main() {\r\n    \/\/ Creating an object 'g' and initializing it with specific values\r\n    Copy g(1, 2, 3, 4, 5, 6, 7, 8);\r\n    \r\n    \/\/ Printing the details of object 'g'\r\n    g.print();\r\n\r\n    \/\/ Creating another object 'h' and initializing it by performing a deep copy of 'g'\r\n    Copy h(g);\r\n\r\n    \/\/ Printing the details of object 'h'\r\n    h.print();\r\n\r\n    return 0;\r\n}\r\n<\/pre>\n<ul>\n<li>\u0625\u0646\u0634\u0627\u0621 \u0627\u0644\u0643\u0627\u0626\u0646 (g):<br \/>\n\u064a\u062a\u0645 \u0625\u0646\u0634\u0627\u0621 \u0643\u0627\u0626\u0646 g \u0645\u0646 \u0627\u0644\u0646\u0648\u0639 Copy \u0648\u062a\u0647\u064a\u0626\u062a\u0647 \u0628\u0642\u064a\u0645 \u0645\u062d\u062f\u062f\u0629.<\/li>\n<li>\u062a\u0641\u0627\u0635\u064a\u0644 \u0627\u0644\u0637\u0628\u0627\u0639\u0629 (g):<br \/>\n\u064a\u062a\u0645 \u0627\u0633\u062a\u062f\u0639\u0627\u0621 \u062f\u0627\u0644\u0629 \u0639\u0636\u0648 \u0627\u0644\u0637\u0628\u0627\u0639\u0629 \u0644\u0639\u0631\u0636 \u062a\u0641\u0627\u0635\u064a\u0644 \u0627\u0644\u0643\u0627\u0626\u0646 g.<\/li>\n<li>\u0625\u0646\u0634\u0627\u0621 \u0627\u0644\u0643\u0627\u0626\u0646 (h):<br \/>\n\u064a\u062a\u0645 \u0625\u0646\u0634\u0627\u0621 \u0643\u0627\u0626\u0646 h \u0622\u062e\u0631 \u0648\u062a\u0647\u064a\u0626\u062a\u0647 \u0639\u0646 \u0637\u0631\u064a\u0642 \u0625\u062c\u0631\u0627\u0621 \u0646\u0633\u062e\u0629 \u0639\u0645\u064a\u0642\u0629 \u0645\u0646 \u0627\u0644\u0643\u0627\u0626\u0646 g \u0628\u0627\u0633\u062a\u062e\u062f\u0627\u0645 copy constructor.<\/li>\n<li>\u062a\u0641\u0627\u0635\u064a\u0644 \u0627\u0644\u0637\u0628\u0627\u0639\u0629 (h):<br \/>\n\u064a\u062a\u0645 \u0627\u0633\u062a\u062f\u0639\u0627\u0621 \u062f\u0627\u0644\u0629 \u0639\u0636\u0648 \u0627\u0644\u0637\u0628\u0627\u0639\u0629 \u0644\u0639\u0631\u0636 \u062a\u0641\u0627\u0635\u064a\u0644 \u0627\u0644\u0643\u0627\u0626\u0646 h.<\/li>\n<\/ul>\n<p>\u0645\u062e\u0631\u062c\u0627\u062a \u0647\u0630\u0627 \u0627\u0644\u0628\u0631\u0646\u0627\u0645\u062c \u0633\u062a\u0643\u0648\u0646 \u0643\u0627\u0644\u062a\u0627\u0644\u064a:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">1 2 3 4 5 6 7 8 \r\n1 2 3 4 5 6 7 8 \r\n<\/pre>\n<p>\u064a\u0648\u0636\u062d \u0647\u0630\u0627 \u0627\u0644\u0643\u0648\u062f \u0627\u0633\u062a\u062e\u062f\u0627\u0645 copy constructor \u0644\u0625\u0646\u0634\u0627\u0621 \u0643\u0627\u0626\u0646 \u062c\u062f\u064a\u062f \u0628\u0646\u0641\u0633 \u0642\u064a\u0645 \u0643\u0627\u0626\u0646 \u0645\u0648\u062c\u0648\u062f\u060c \u0645\u0645\u0627 \u064a\u0636\u0645\u0646 \u0646\u0633\u062e\u0629 \u0639\u0645\u064a\u0642\u0629 \u0645\u0646 \u0627\u0644\u0628\u064a\u0627\u0646\u0627\u062a.<\/p>","protected":false},"excerpt":{"rendered":"<p>What is a Constructor? In C++, a constructor is a special member function within a class that is automatically invoked when an object of that class is created. Its primary purpose is to initialize the object&#8217;s data members or perform any necessary setup for the object. Constructors ensure that the object starts with a valid [&hellip;]<\/p>","protected":false},"author":1,"featured_media":0,"parent":4291,"menu_order":42,"comment_status":"closed","ping_status":"closed","template":"","doc_tag":[],"class_list":["post-6037","docs","type-docs","status-publish","hentry","no-post-thumbnail"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/docs\/6037","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/comments?post=6037"}],"version-history":[{"count":11,"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/docs\/6037\/revisions"}],"predecessor-version":[{"id":10436,"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/docs\/6037\/revisions\/10436"}],"up":[{"embeddable":true,"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/docs\/4291"}],"wp:attachment":[{"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/media?parent=6037"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/doc_tag?post=6037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}