2012-04-29 2 views
0

C:\Users\George\Desktop\linear_equation_calc\main.cpp||In function 'int main(int, const char**)':| C:\Users\George\Desktop\linear_equation_calc\main.cpp|101|error: 'calcparallelplugin' was not declared in this scope| ||=== Build finished: 1 errors, 0 warnings ===|1 최종 컴파일러 오류가 :(사람이 내가 점점 계속 오류 나를

에 대한 실제 간단한 설명 할 수 있습니다. 나는 정말 생각 메신저가를 사용하여 메신저로 선언하는 방법을 이해 해달라고 jsut 어떤 수단을 선언하지만 이해 calcparallelplugin() 다른 .cpp 파일에 연결합니다. 나는 별도의 .cpp 파일 및 머리글이없는 표준 연습 알고 있습니다. 누군가가 정말 간단한 용어로 제발, 설명해주세요. 나는 순간처럼 *** ***

#include <iostream> 
#include <string.h> 

using namespace std; 

// Function includes 
// I try to keep them in the order they appear in the 
// output below for organization purposes 
#include "calc.m.xy12plugin.cpp" 
#include "calc.b.xymplugin.cpp" 
#include "calc.m.xybplugin.cpp" 
#include "calc.point.xymplugin.cpp" 
#include "calc.parallelplugin.cpp" 

// The above one would be here, too 

int main(int argc, const char* argv[]) { 
    int i; 
    i = 0; 
    cout << "Linear Equation Calculator" << endl << "Copyright (c) 2011 Patrick Devaney" << endl 
    << "Licensed under the Apache License Version 2" << endl; 
    // This loop makes the code a bit messy, 
    // but it's worth it so the program doesn't 
    // crash if one enters random crap such as 
    // "zrgxvd" or "54336564358" 
    while(i < 1) { 
    cout << "Type:" << endl 
    << "0 to calculate a slope (the M value) based on two points on a line" << endl 
    << "1 to calculate the Y-intercept (the B value) based on two points and a slope" << endl 
    << "2 to calculate the slope (the M value) based on the Y-intercept and X and Y" << endl << 
    "plug-ins" << endl 
    << "3 to find the next point up or down a line based on the slope (M) and X and Y" 
    << endl << "plug-ins" << endl 
    << "4 to find a point x positions down the line based on the slope (M) and X and Y" 
    << endl << "plug-ins" << endl 
    << "5 to find the equation of a parallel line in form y=mx+c" 
    << endl << "plug-ins" << endl; 

    string selection; 
    cin >> selection; 
    if(selection == "0") { 
     mcalcxyplugin(); 
     i++; 
    } 
    else if(selection == "1") { 
     calcbxymplugin(); 
     i++; 
    } 
    else if(selection == "2") { 
     calcmxybplugin(); 
     i++; 
    } 
    else if(selection == "3") { 
     calcpointxymplugin(1); 
     i++; 
    } 
    else if(selection == "4") { 
     int a; 
     cout << "How many points up/down the line do you want? (Positive number for points" << endl 
     << "further up, negative for previous points" << endl; 
     cin >> a; 
     calcpointxymplugin(a); 
     i++; 
    } 
    else if(selection == "5"){ 

     calcparallelplugin(); 
     i++; 
    } 
    else { 
     i = 1; 
    } 
    // End of that loop below 
    } 
    return 0; 
} 
+1

1. 심각하게 - _code_가'.cpp' 파일에 있고'.h' 파일에 선언되어 있도록 코드를 수정하십시오. 2. 소스의 일부를 보여주지 않으면 함수가 분명히 선언되지 않은 이유를 어떻게 알 수 있습니까? – Alnitak

+2

이것은 내 눈을 공격하는 코드를 포맷하십시오! 헤더 파일에서 메소드에 대한 인터페이스를 실제로 정의해야하고 구현 세부 사항 인 cpp 파일이 아닌 헤더 파일을 포함해야합니다. – EdChum

+0

@Alnitak 3. 더 많은 답변을 수락하십시오! – imulsion

답변

3

이 범위에서 선언되지 않은 오류는 정확하게 의미합니다. #include<...> 개의 파일이 모두 주 파일에 포함 된 후 컴파일러에서 해당 파일을 찾지 못했습니다. 함수이므로, 무엇을 해야할지 모릅니다.

그러나, 이는 또한 다른 경우에 적용

이때
#include <iostream> 

int main(int argc, char** argv) 
{ 
    testfunc(); 
} 

void testfunc() 
{ 
    std::cout << "test!" << std::endl; 
} 

문제에 대한 이유는 컴파일러 순방향 선언하는 기능을 필요로 - 그것은 함수 원형 필요 즉. 이것은 작동합니다 : 범위 지정에 관해서는 다른 경우가있다

#include <iostream> 

void testfunc(); // the compiler sees this and knows the linker 
       // has the responsibility of finding this symbol. 

int main(int argc, char** argv) 
{ 
    testfunc(); 
} 

void testfunc() 
{ 
    std::cout << "test!" << std::endl; 
} 

, 너무. 네임 스페이스는 범위에 영향을 미치므로 예 :

#include <iostream> 

void testfunc(); 

int main(int argc, char** argv) 
{ 
    testfunc(); 
} 

namespace test 
{ 
    void testfunc() 
    { 
     std::cout << "test!" << std::endl; 
    } 
} 

또한 실패합니다. 프로토 타입의 경우 void test::testfunc();이 필요합니다. 이것은 전역 범위 ::과는 달리 네임 스페이스의 내부가 자체 범위의 범위이기 때문입니다. 코드에 using namespace std;을 쓰면 전역 네임 스페이스에서 사용할 수있는 std의 함수를 사용할 수있게됩니다.

또한 포함 항목에 .cpp을 사용했음을 확인했습니다. 규칙은 헤더 파일에 .h 또는 .hpp을 사용하며, 해당하는 .cpp 구현에 대해 전달 선언, 클래스 등을 포함하는 경우가 많습니다.

그래서, 나는 그것을 확인합니다 :

  • 코드가 namespace'd되지 않습니다.
  • 당신은 옳은 것을 포함하고 있습니다.
  • 올바른 이름의 함수를 호출하고 있습니다.
관련 문제