2014-09-24 78 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