简体   繁体   中英

Program not building on Visual studio

The above shows the error I am getting when I build main.cpp from Microsoft Visual Studio
main.cpp file

       #include <iostream>
    #include "catalan.h"
    using namespace std;
    int main()
    {
        int selection;
        int number;
       
        }
        return 0;
}

This is the catalan.h file:

#include "implementation.cpp"
int catalan(int n);
int fibonacci(int x);
void menu();

This is the implementation.cpp file

int catalan(int n)
{
    if (n <= 1)
        return 1;
    int result = 0;
   

    return result;
}
int fibonacci(int x)
{
    return 0;
}
void menu()
{
    std::cout << "1. Do Catalan numbers" << std::endl;
 
}

I have removed some code from it for ease in readability. This same program is compiling
and running fine with g++ But when I put it on Microsoft Visual Studio it doesnt compile.
What could be the reason for it and how do it correct it? The image of error screenshot can be seen at -

错误快照:-(

Don't include .cpp files like you do in #include "implementation.cpp" . Include header files and compile .cpp files.

When you've removed #include "implementation.cpp you may be required to add missing #include s to the .cpp file if it currently relies on that you've done #include <iostream> for example.

Compiling:

In g++ , it would mean compiling this this:

g++ main.cpp implementation.cpp -o program_name

In Visual Studio it would mean adding the missing .cpp file to the project. It should be either main.cpp or implementation.cpp .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM