2014-09-24 73 views
-1

我得到这个奇怪的错误通。当我搜索更多关于它的时候,它说功能没有定义,但是我在代码的底部定义了它。希望有人能帮助得到一个奇怪的错误与参考C++

Ld /Users/Bartski/Library/Developer/Xcode/DerivedData/areaProject-gfmvmiwbtmgqwggbbwbylymlgbvo/Build/Products/Debug/areaProject normal x86_64 
cd "/Users/Bartski/Desktop/School/Fall 2014/CIS 265/areaProject" 
export MACOSX_DEPLOYMENT_TARGET=10.10 
/Applications/Xcode6-Beta7.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode6-Beta7.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -L/Users/Bartski/Library/Developer/Xcode/DerivedData/areaProject-gfmvmiwbtmgqwggbbwbylymlgbvo/Build/Products/Debug -F/Users/Bartski/Library/Developer/Xcode/DerivedData/areaProject-gfmvmiwbtmgqwggbbwbylymlgbvo/Build/Products/Debug -filelist /Users/Bartski/Library/Developer/Xcode/DerivedData/areaProject-gfmvmiwbtmgqwggbbwbylymlgbvo/Build/Intermediates/areaProject.build/Debug/areaProject.build/Objects-normal/x86_64/areaProject.LinkFileList -mmacosx-version-min=10.10 -stdlib=libc++ -Xlinker -dependency_info -Xlinker /Users/Bartski/Library/Developer/Xcode/DerivedData/areaProject-gfmvmiwbtmgqwggbbwbylymlgbvo/Build/Intermediates/areaProject.build/Debug/areaProject.build/Objects-normal/x86_64/areaProject_dependency_info.dat -o /Users/Bartski/Library/Developer/Xcode/DerivedData/areaProject-gfmvmiwbtmgqwggbbwbylymlgbvo/Build/Products/Debug/areaProject 

Undefined symbols for architecture x86_64: 
    "circle_area(float&)", referenced from: 
     _main in main.o 
    "square_area(float&)", referenced from: 
     _main in main.o 
    (maybe you meant: __Z11square_areaRfS_) 
    "rec_area(float&, float&)", referenced from: 
     _main in main.o 
    (maybe you meant: __Z8rec_areaRfS_S_) 
ld: symbol(s) not found for architecture x86_64 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 

源代码:

#include <iostream> 
#include <stdlib.h> 

using namespace std; 

// prototypes of functions 

void input_function(float&); 
void input_function2(float&, float&); 
void output_function(float); 
void circle_area(float&); 
void square_area(float&); 
void rec_area(float&, float&); 

int main(int argc, const char* argv[]) { 
    // initialization of variables 

    float input_one; 
    float input_two; 
    float area; 
    int choice; 
    char repeat; 

    do { 
     cout << "please choose which shape you would like to use, 1 for " 
       "circle, 2 for square, 3 for rectangle" << endl; 
     cin >> choice; 

     // user chooses which area to calculate 

     switch (choice) { 
      case 1: 
       cout << "Please enter the radius of the circle" << endl; 
       input_function(input_one); 
       circle_area(input_one); 
       cout << "The area of the circle is " << area << endl; 
       break; 

      case 2: 
       cout << "Please enter the lenght of the square side" << endl; 
       input_function(input_one); 
       square_area(input_one); 
       cout << "The area of the square is " << area << endl; 
       break; 

      case 3: 
       cout << "Please enter the lenght of the rectangle height" 
        << endl; 
       input_function2(input_one, input_two); 
       rec_area(input_one, input_two); 
       break; 
     } 
     cout << "would you like to do it again? y/n " << endl; 
     cin >> repeat; 
    } while (repeat == 
      'y'); // repeats if user puts y, ends if anything else is entered 

    return 0; 
} 

// this function gets the input from the user 

void input_function2(float& input_one, float& input_two) { 
    cout << "please enter the lenght and the width of the rectangle"; 
    cin >> input_one; 
    cin >> input_two; 
} 

void input_function(float& input_one) { 
    cin >> input_one; 

    while (input_one < 0) { 
     cout << "the dimension cannot be less then 0, please enter again" 
      << endl; 
     cin >> input_one; 
    } 
} 

// this function calculates the area of the circle 

void circle_area(float& input_one, float& area) { 
    float const pi = 3.14159; 
    area = input_one * input_one * pi; 
} 

// this function calculates the area of the square 

void square_area(float& input_one, float& area) { 
    area = input_one * input_one; 
} 

// this function calculates the area of the rectangle 

void rec_area(float& input_one, float& input_two, float& area) { 
    area = input_one * input_two; 
} 

// this function outputs the area to the console 

void output_function(float& area) { cout << area; } 

回答

1

你宣布你的函数取一个参数,但随后他们定义以两个。编译器,这是两个不同的功能,因此链接器无法解析引用,因此错误:

改变所有的错配声明取两个参数,而不是一个。

+0

工作。非常感谢你 – 2014-09-24 01:46:54