c++ - 使用未声明的标识符 'FunctionName' C++ Xcode

标签 c++ xcode undeclared-identifier

我想做的只是从另一个函数调用一个简单的函数,为什么我每次在 convert_to_Roman 函数中调用 addRomanDigit 时都会出错?该程序未完成我只是想完成第一个功能。

//
//  RomanCalculator.cpp
//  HelloWorld
//
//  Created by Feroze on 6/13/13.
//  Copyright (c) 2013 Feroze Shahpurwala. All rights reserved.
//

#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>

using namespace std;


string convert_to_Roman(int value)
{
    string retVal;
   /* if (value < 0)
    {
        retVal ="-";
        value = -value;
    } */

    retVal = addRomanDigit(retVal, value/1000, 'M'); // ERROR HERE and for one below 'Use of undeclared identifier 'addRomanDigit'
    value = value % 1000;
    retVal = addRomanDigit(retVal, value/500,  'D');
    value = value % 500;
    retVal = addRomanDigit(retVal, value/100,  'C');
    value = value % 100;
    retVal = addRomanDigit(retVal, value/50,   'L');
    value = value % 50;
    retVal = addRomanDigit(retVal, value/10,   'X');
    value = value % 10;
    retVal = addRomanDigit(retVal, value/5,    'V');
    value = value % 5;
    retVal = addRomanDigit(retVal, value,      'I');

    return retVal;
}


string addRomanDigit(string starting, int num, char digit)
{
    string retval = starting;
    for (int i=0; i < num; i++)
        retval += digit;
    return retval;
}


int convert_from_Roman(int x)
{
    return 0;
}

int calc_romans(/*figure out the calling sequence*/)
{
    // fill in your code
    // We will be discussing the string class in more detail in
    // subsequent chapters.  The following snippet illustrates a few
    // features we will encounter :

    // string str = "abcdefg";
    // for (int i=0; i < str.length(); i++)
    // {
    //     char c = str[i];  // pull of characters one at a time from the string
    // }

}


void print_Result(/* figure out the calling sequence */)
{
    // fill in your code
}

// Note the call by reference parameters:
void get_Data(ifstream & infile, string & operand1, string & operand2, char & oper, bool & badInput)
{
    // Read in operand1, operand2, oper
    // Check to see if an error condition has occurred.
    // Set badInput for any error, but main will only print out an error condition
    // if the reason for the error is something other than
    // hitting an end of file(out of data) condition.

    //
}

// I would rather have you leave main alone and just make your function calls above match
// the calling sequence required by main below:

int main()
{
    ifstream infile;
    infile.open("roman.txt");
    if (!infile)
    {
        cout << "Can't open roman.txt" << endl;
        return -1;
    }

    while(!infile.eof())
    {
        string operand1, operand2;
        char oper;
        bool badInput;
        get_Data(infile, operand1, operand2, oper,  badInput);

        if (badInput)
        {
            if (!infile.eof()) // Check to see if we are the end of the file
                cout << "Skipping Bad input"<<endl;  // Must be a bad input
        }
        else
        {
            int value1 = convert_from_Roman(operand1);
            int value2 = convert_from_Roman(operand2);
            cout << "The first operand is " << operand1 <<
            "(" << value1 << ")"<<endl;
            cout << "The second operand is " << operand2 <<
            "(" << value2 << ")"<<endl;
            cout <<"The operator is " << oper << endl;
            int answer = calc_romans(value1, value2, oper);
            print_Result(operand1, operand2, convert_to_Roman(answer), answer);
            cout << endl;
        }
    }

}

最佳答案

您应该将函数声明 addRomanDigit 放在 convert_to_Roman 之前

 string addRomanDigit(string starting, int num, char digit);
 string convert_to_Roman(int value)
 {
     //... function body 
 }

或者简单地将addRomanDigit的函数定义移到convert_to_Roman之前。

关于c++ - 使用未声明的标识符 'FunctionName' C++ Xcode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17098515/

相关文章:

c++ - 如何从具有特定值的 STL vector 中删除项目?

c++ - 在Qt中,如何确定屏幕的大小?

c++ - 在 Fortran 程序中使用 Boost 图形库 (BGL)

iphone - 创建自定义 UIButton 类

java - 高性能流数据处理问题

ios - Swift NFC Mifare - 不支持 NFCISO7816APDU sendMifare 命令

c++ - 如何为 iphone 编译一个简约的 cpp Protocol Buffer 库?

c - 错误 : 'Math' undeclared first use in this function

objective-c - 使用未声明的标识符错误

c++ - 为什么编译器对我在上面的 "undeclared identifier"语句中声明的变量说 "if"?