Well, in the first code snippet, a
;
is missing after the class declaration
public ref class Simulate
{
};
In this is the case, then the compiler would try to append to the declaration whatever it find afterward...
Next, you will have to ensure that the file is indeed include using
#error testing inclusion...
A file might not be include is a file similary named exists elsewhere and it picked up. Also, it might happen when include guard are uses to prevent multiple inclusion of the same file. A common case where this is a problem is when a file is copied from another one and include guard are not properly updated. This problem is eliminated is you uses
#pragma once
. Include guard are something like:
simulate.h
#ifndef SIMULATE_H // Might be problematic if incorrect (after cut & paste)
#define SIMULATE_H
public ref class Simulate
{
};
#endif
It is easier to replace those 3 extra lines with
#pragma once
when the code does not need to be portable on a compiler that does not support it.
Another thing to check is which source file is being compiled when the error occurs. Since the missing reference is in
"Form1.h"
one can assume that the error was occuring while compiling
"Form1.cpp"
but if the file is included from multiple location this might not be the case. And if the
#include
is not inside
"Form1.h"
and the other source file that uses
"Form1.h"
does not uses precompiled headers (does not include
"stdafx.h"
or options set to use them), then it can go wrong.
The best way to find such problem is to do a "clean" the compile
"stdafx.cpp"
and then compile each file one by one (starting by the suspect ones like
"Form1.cpp"
). Doing that (and also with the
#error
trick), you should be able to find what is done incorrectly.
Renaming files and/or class to see if the problem persist might help to identify possible conflict. Or in some case move code around or comment out some blocks of code. Often it is a small mistake that we simply does not see. All those tricks help to find the cause when we don't see it.