简体   繁体   中英

C++ compiler error in CodeBlocks & Xcode

I'm currently learning to become a programmer and while I was learning I came across a bit of a problem. This program doesn't run and gives me an error

clang: error: linker command failed with exit code 1 (use -v to see invocation)

Why is this and how do I fix it and prevent it from happening again?

#include <iostream>
using namespace std;

void Fav();
int main()
{
    Fav();
    return 0;
}
void Fav(int x)
{
    cout<<"Troy's Favorite Number is \n"<<x;
}

The declared function and defined function are different. They are therefore different functions, the former of which is never defined, even though it is called in main

void Fav();      // Declared
void Fav(int x)  // Defined

You need to change the signature of the declared function to matche the declared and called function

void Fav(int x);
int main()
{
    int x;
    cin >> x;
    Fav(x);
    return 0;
}

void Fav(int x)
{
    cout<<"Troy's Favorite Number is \n" << x;
}

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