what is a header in c++
C++
// my_program.cpp
#include "my_class.h"
using namespace N;
int main()
{
my_class mc;
mc.do_something();
return 0;
}
// my_class.h
namespace N
{
class my_class
{
public:
void do_something();
};
}
// my_class.h
#ifndef MY_CLASS_H // include guard
#define MY_CLASS_H
namespace N
{
class my_class
{
public:
void do_something();
};
}
#endif /* MY_CLASS_H */
// my_class.cpp
#include "my_class.h" // header in local directory
#include <iostream> // header in standard library
using namespace N;
using namespace std;
void my_class::do_something()
{
cout << "Doing something!" << endl;
}
int x; // declaration
x = 42; // use x
// sample.h
#pragma once
#include <vector> // #include directive
#include <string>
namespace N // namespace declaration
{
inline namespace P
{
//...
}
enum class colors : short { red, blue, purple, azure };
const double PI = 3.14; // const and constexpr definitions
constexpr int MeaningOfLife{ 42 };
constexpr int get_meaning()
{
static_assert(MeaningOfLife == 42, "unexpected!"); // static_assert
return MeaningOfLife;
}
using vstr = std::vector<int>; // type alias
extern double d; // extern variable
#define LOG // macro definition
#ifdef LOG // conditional compilation directive
void print_to_log();
#endif
class my_class // regular class definition,
{ // but no non-inline function definitions
friend class other_class;
public:
void do_something(); // definition in my_class.cpp
inline void put_value(int i) { vals.push_back(i); } // inline OK
private:
vstr vals;
int i;
};
struct RGB
{
short r{ 0 }; // member initialization
short g{ 0 };
short b{ 0 };
};
template <typename T> // template definition
class value_store
{
public:
value_store<T>() = default;
void write_value(T val)
{
//... function definition OK in template
}
private:
std::vector<T> vals;
};
template <typename T> // template declaration
class value_widget;
}
Also in C++:
- Title
- how to execute c++ program in cmd
- Category
- C++
- Title
- comparing strings c++
- Category
- C++
- Title
- variabvles in c++
- Category
- C++
- Title
- std::iomanip c++
- Category
- C++
- Title
- minimum swaps to sort an array
- Category
- C++
- Title
- how to ensure the user inouts a int and not anything else c++
- Category
- C++
- Title
- string substr c++
- Category
- C++
- Title
- tellg and seekg c++
- Category
- C++
- Title
- how to compare two strings lexicographically in c++
- Category
- C++
- Title
- how to get the largest number in a c++ array
- Category
- C++
- Title
- how the theam are store in database
- Category
- C++
- Title
- placement new c++
- Category
- C++
- Title
- min and max heap in cpp
- Category
- C++
- Title
- c++ typeid get type name
- Category
- C++
- Title
- how to avoid tle in c++
- Category
- C++
- Title
- error: ISO C++ forbids comparison between pointer and integer [-fpermissive] if(s[i] != "b"){
- Category
- C++
- Title
- primeros numeros primos
- Category
- C++
- Title
- c++ read matttrix from text file
- Category
- C++
- Title
- self in c++
- Category
- C++
- Title
- create a dictionary cpp
- Category
- C++
- Title
- c++ remove element from vector
- Category
- C++
- Title
- c++ menu selection with arrow keys
- Category
- C++
- Title
- calculate factorial
- Category
- C++
- Title
- remove value from vector c++
- Category
- C++
- Title
- c++ std::copy to cout
- Category
- C++
- Title
- c++ short if
- Category
- C++
- Title
- char **
- Category
- C++
- Title
- c++ for loop syntax
- Category
- C++
- Title
- c++ try
- Category
- C++
- Title
- c++ print one line to console instead of multiple
- Category
- C++
- Title
- how to iterate over unordered_map c++
- Category
- C++
- Title
- c++ give options
- Category
- C++
- Title
- C++ remove element from set
- Category
- C++
- Title
- Newton's sqrt in c++
- Category
- C++
- Title
- cloud hosting
- Category
- C++
- Title
- variabili in c++
- Category
- C++
- Title
- Application of c++ in youtube program
- Category
- C++
- Title
- map.erase in c++
- Category
- C++
- Title
- log base 10 c+_+
- Category
- C++
- Title
- c++ unittest in ros
- Category
- C++
- Title
- % operator in c++
- Category
- C++
- Title
- regexp_like oracle c++
- Category
- C++
- Title
- flake8 max line length
- Category
- C++
- Title
- filling 2d array with 0 c++
- Category
- C++
- Title
- c++ overloaded == operator
- Category
- C++
- Title
- friend function in c++
- Category
- C++
- Title
- how to switch to another branch in git
- Category
- C++
- Title
- pionter in c++
- Category
- C++
- Title
- c++ string to stream
- Category
- C++
- Title
- remove item from layout
- Category
- C++
- Title
- sum of vector c++
- Category
- C++
- Title
- c++ program how to let the user choose different game modes
- Category
- C++
- Title
- convert int to binary string c++
- Category
- C++
- Title
- pop from between string c++
- Category
- C++
- Title
- Find the minimum difference between pairs in a simple path of tree C++
- Category
- C++
- Title
- initialize vector of pointers c++
- Category
- C++
- Title
- popualte an array c++
- Category
- C++
- Title
- get data from terminal c++
- Category
- C++
- Title
- check if key exists in map c++
- Category
- C++
- Title
- c++ function return array
- Category
- C++
- Title
- count function c++
- Category
- C++
- Title
- how to run c++ file mingw cmd
- Category
- C++
- Title
- Find a element in a map C++
- Category
- C++
- Title
- assegnare valori in c++
- Category
- C++
- Title
- c++ string contains
- Category
- C++
- Title
- Find the duplicate in an array of N integers.
- Category
- C++
- Title
- initialize 3d vector c++
- Category
- C++
- Title
- c++ convert int to double
- Category
- C++
- Title
- primos menores que
- Category
- C++
- Title
- how to modulo 10^9+7
- Category
- C++
- Title
- stringstream in c++ with delimiter
- Category
- C++
- Title
- expected initializer before 'isdigit'|
- Category
- C++
- Title
- c++ program for addition of two numbers using functions
- Category
- C++
- Title
- c++ client service ros
- Category
- C++
- Title
- convert char to string - c++
- Category
- C++
- Title
- programa para saber si un numero es primo
- Category
- C++
- Title
- ios_base::sync_with_stdio(false);cin.tie(NULL);
- Category
- C++
- Title
- lopping over an array c++
- Category
- C++
- Title
- C++ pointer arithmetic
- Category
- C++
- Title
- how to declare a vector in c++
- Category
- C++
- Title
- command line options in c++
- Category
- C++
- Title
- can we compare a long long int with int in c++ using max or min functions
- Category
- C++
- Title
- making random numbers in c++
- Category
- C++
- Title
- c++ return multiple values
- Category
- C++
- Title
- function declerations in C++
- Category
- C++
- Title
- substitution failure is not an error
- Category
- C++
- Title
- How to find the suarray with maximum sum using divide and conquer
- Category
- C++
- Title
- check for bst
- Category
- C++
- Title
- initialize int c++
- Category
- C++
- Title
- how to make a switch case statement in c++
- Category
- C++
- Title
- c++ string^ to char*
- Category
- C++
- Title
- clear qlayout
- Category
- C++
- Title
- change int to string cpp
- Category
- C++
- Title
- length of string in c++
- Category
- C++
- Title
- sort a pair using c++ stl
- Category
- C++
- Title
- system("pause") note working c++
- Category
- C++
- Title
- sfml basic program
- Category
- C++
- Title
- lambda c++
- Category
- C++
- Title
- how to know the correct class of objects cpp
- Category
- C++
- Title
- printf c++
- Category
- C++