From 2bad31193ba435bee645f6d9635c75ddb4b8d106 Mon Sep 17 00:00:00 2001 From: nagrat Date: Tue, 14 Mar 2023 15:43:10 +0000 Subject: [PATCH] Added header files --- Header Files/header.cpp | 11 +++++++++++ Header Files/header.h | 16 ++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 Header Files/header.cpp create mode 100644 Header Files/header.h diff --git a/Header Files/header.cpp b/Header Files/header.cpp new file mode 100644 index 0000000..829ff8f --- /dev/null +++ b/Header Files/header.cpp @@ -0,0 +1,11 @@ +#include +#include "header.h" // this is the header file I have made + +using namespace std; +using namespace Header; // made a namespace from the header file and now accessing it + +int main() { + MyHeader mh; // taking the class and defining an object + cout << mh.name << endl; // prints "this is my header name" + cout << mh.age << endl; // prints "19" +} \ No newline at end of file diff --git a/Header Files/header.h b/Header Files/header.h new file mode 100644 index 0000000..a4779a2 --- /dev/null +++ b/Header Files/header.h @@ -0,0 +1,16 @@ +#pragma once // ensures that the header file is only included once and not all the time during compiling + +#ifndef HEADER // if not defined +#define HEADER // define HEADER + +#include + +namespace Header { // defines the header for the main file to "using namespace " stuff + class MyHeader { // define header + public: // public access identifier + std::string name = "this is my header name"; // makes a variable called name + int age = 19; // makes a variable assigned to int 19 + }; +} + +#endif // end the ifndef at line 3 \ No newline at end of file