Visual Studio, #pragma once not working?

Software development can sometimes be a comical affair, I have just been caught out badly by a strange gotcha – it appeared that #pragma once stopped working on a Visual Studio C++ project on which I have been working.  I was getting plenty of error messages about redefined classes!

Well it turns out that I had left a copy of one of my header files lying around in one of the project folders.  As pragma once uses a header file’s full path to figure out if it has already opened it, a situation arose whereby both files were included and compile errors flooded in (despite the pragma onces)!

Well removing the (accidential) copy of the header file fixed the problem – boy do I feel stupid, I hope this post may help someone with a similar problem in the future!

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *