0

我在尝试向 RealList 结构中添加内容的行中的方法 SetNameandOp 中的运行时出现标题错误。我想我引用 RealList 是错误的,但我不知道如何纠正它。有人有什么想法吗?

以下是头文件中的结构:

     class Instructions
    {
    public:

       //methods
        struct myInstruction
        {
            string name;
            string opcode; //opcode of add, addi etc.
            string rs; //2nd paramter
            string rt; //3rd
            string rd; //1st 
            string shamt; //shift amount
            string function; 
            myInstruction* next;
        }InstructionList;
}

class greenCard
{
public:
    //methods

    struct 
    {
        string name;
        string opcode;
        string function;
    } Instructions[29];
}

方法:

Instructions::InputtedInstructions* Instructions::get_instruction(vector<string>& vec, int counter)
{   
    InputtedInstructions* InputList = new InputtedInstructions[counter];
    myInstruction* RealList = new myInstruction[counter];
    while (ListPosition != counter)
    {

        string text = vec.at(ListPosition);
        istringstream iss(text);
        string command, arg1, arg2, arg3;

        int CommaAmount = count(text.begin(), text.end(), ',');

        if (CommaAmount == 2)
        {
            while( iss >> command >> arg1 >> arg2 >> arg3)
            {
                setNameandOp(RealList, InputList[ListPosition].name, counter);
                ListPosition++;
            }
        }
    }

    return InputList;
}   

void Instructions::setNameandOp(myInstruction* RealList, string set, int counter)
{
    greenCard NameSet;
    int y = NameSet.instructionsearch(set);
    if (y != -1)
    {
        RealList[counter].name = NameSet.Instructions[y].name;
        RealList[counter].opcode = NameSet.Instructions[y].opcode;
        RealList[counter].function = NameSet.Instructions[y].function;
    }


}

int greenCard::instructionsearch(string realinstruction)
{
    int i;
    for (i=0; i < 29; i++)
    {
        if ( realinstruction.compare(Instructions[i].name) == 0)
            return i; 
    }
    return -1;
}

如果有任何不清楚的地方,请告诉我。如果需要,我很乐意更深入地解释。我只是不确定还有什么可以毫无疑问地提出。

4

0 回答 0