Skip to content
Permalink
Browse files
Added header files
  • Loading branch information
nagrat committed Mar 14, 2023
1 parent 5c4cc6b commit 2bad31193ba435bee645f6d9635c75ddb4b8d106
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
@@ -0,0 +1,11 @@
#include <iostream>
#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"
}
@@ -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 <iostream>

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

0 comments on commit 2bad311

Please sign in to comment.