This file contains hidden or 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
#ifndef TIME_H | |
#define TIME_H | |
struct Time { | |
int hour; | |
int minute; | |
}; | |
void printTime(Time t); | |
#endif |
This file contains hidden or 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
#ifndef A_UNIQUE_HEADER_FILE_GUARD_NAME | |
#define A_UNIQUE_HEADER_FILE_GUARD_NAME | |
// header file content | |
... | |
#endif |
This file contains hidden or 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
struct Time{ | |
int hour; | |
int minutes; | |
}; | |
struct Time{ | |
int hour; | |
int minutes; | |
}; |
This file contains hidden or 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
... | |
// replaced from first #include "time.h" | |
struct Time { | |
int hour; | |
int minute; | |
}; | |
... | |
// replaced from #include "util.h" which also include "time.h" | |
struct Time { | |
int hour; |
This file contains hidden or 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
$ g++ -c main.cpp | |
In file included from util.h:1:0, | |
from main.cpp:3: | |
time.h:1:8: error: redefinition of ‘struct Time’ | |
struct Time { | |
^~~~ | |
In file included from main.cpp:2:0: | |
time.h:1:8: note: previous definition of ‘struct Time’ | |
struct Time { | |
^~~~ |
This file contains hidden or 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
#include <iostream> | |
#include "time.h" | |
#include "util.h" | |
int main(){ | |
Time t; | |
t.hour = 2; | |
t.minute = 10; | |
printTime(t); | |
std::cout << "is Day time? " << isDayTime(t) << std::endl; |
This file contains hidden or 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
#include "time.h" | |
bool isDayTime(Time d); |
This file contains hidden or 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
struct Time { | |
int hour; | |
int minute; | |
}; | |
void printTime(Time t); |
This file contains hidden or 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
struct Point { | |
int x; | |
int y; | |
}; | |
enum Color { black = 0, white = 1, grey = 2}; | |
Point p; | |
Color c = Color::black; |
This file contains hidden or 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
#include "util.h" | |
int main(){ | |
// set to 9:10 | |
Time t(9, 10); | |
return isDayTime(t); | |
} |