Ask coding questions

← Back to all posts
how do i make the main file a header file
jnrchewie (3)

it is warning me that the main file is not a header file and that i cannot use a #pragma once because of this

Comments
hotnewtop
DynamicSquid (4921)

You can not use #pragma once in .cpp files, only in .h files

jnrchewie (3)

@DynamicSquid but .h files don't work and the pragma once is needed to stop a loop

DynamicSquid (4921)

@jnrchewie no, .h files are for declarations, and .cpp file are for implementations like this:

// main.cpp
#include "game.h"
int main() {}


// game.h
#pragma once
void play_game(int score);


// game.cpp
#include "game.h"
void play_game(int score) {}

It gets a little complicated, so you can instead just use a .h file like this:

// main.cpp
#include "game.h"
int main() {}


// game.h
#pragma once
void play_game(int score) {}