Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |