English 中文(简体)
范围差错
原标题:scope error message

He,只是学习班级的构成,并出现这一错误。

Gradebook.h

  #ifndef GRADEBOOK_h
#define GRADEBOOK_h

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

class GradeBook
{
public:
    GradeBook();

    GradeBook(string initLastName, int studGrades);

    void AddStudent(string initLastName, int studGrades);

    void ShowStudents();

    void UserInterface();

private:
    static const int numStudents=20;
    StudentRec student[numStudents];
    static int studentCounter;
    static int gradeCounter;
};

#endif 

<>strong>Gradebook.cpp

     #include "Gradebook.h"
#include "StudentRec.h"
#include <iostream>
#include <string>

using namespace std;

GradeBook::GradeBook()
{}

GradeBook::GradeBook(string initLastName, int studGrades)
{}

void GradeBook::AddStudent(string initLastName, int studGrades)
{   
    gradeCounter++;   //Increments variable responsible for tracking # of grades per student
    StudentRec newStudent(initLastName, studGrades); //creates new student object
    student[studentCounter]=newStudent;  //Assigns new student object to array
    studentCounter++;  //Increments variable responsible for tracking # of students
}

void GradeBook::ShowStudents()
{
    for(int i=0;i<studentCounter; i++){  //Displays information for each student instance
        cout<<student[i].GetLastName()<<   ;
        for(int j=0; j<gradeCounter; j++)        
            cout<<student[i].GetGrades(j)<<   ;
        cout<<endl;
    }
}

void GradeBook::UserInterface()
{
    char choice=   ;
    string studLastName;
    int studGrade;

    cout<<"Welcome to GradeBook, this program stores students"
    <<" grades by last name.  To ADD a student press the  A "
    <<" key.  To LIST all students, press the  L  key.  To "
    <<" QUIT, press the  Q  key."<<endl<<endl;

    cin>>choice;

    choice=toupper(choice);

    while(choice!= Q )
    {
        if(choice= A ){
            cout<<"To add a student, please enter their last name"
            <<" followed by a space and a non-negative grade"
            <<" Ex. McClure 96";
            cin>>studLastName>>studGrade;

            AddStudent(studLastName, studGrade);
        }

        else if(choice= L ){
            cout<<"This is a list of all students in GradeBook"
            <<endl<<endl;

            ShowStudents(); //Displays all StudentRec objects
        }

        else if(choice!= Q )
            cout<<"Please enter another letter"<<endl;

        cout<<"To ADD a student press the  A  key.  To LIST all students, press the  L  key.  To "
        <<" QUIT, press the  Q  key."<<endl<<endl;      
    }
}

www.un.org/Depts/DGACM/index_french.htm

    #include <iostream>
    #include <string>
#include "StudentRec.h"
#include "Gradebook.h"

using namespace std;

int main()
{
    GradeBook gradeBook;

    UserInterface();

    return 0;

}

<>StudentRec.cpp

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

using namespace std;

StudentRec::StudentRec()
{
    lastName=" ";
    for(int i=0;i<numGrades; i++)
        grades[i]=0;
}

StudentRec::StudentRec(string initLastName, int studGrade)
{
    static int gradeCounter=0;
    lastName=initLastName;
    grades[gradeCounter]=studGrade;
}

string StudentRec::GetLastName()
{
    return lastName;
}

int StudentRec::GetGrades(int gradeNum)
{
    return grades[gradeNum];
}

void StudentRec::AddGrades(int studGrade)
{

    gradeCounter++;
    if(gradeCounter<=numGrades)
        grades[gradeCounter]=studGrade;
    else
        cout<<"Too many grades for this student";
}

<>StudentRec.h

#ifndef STUDENTREC_h
#define STUDENTREC_h

#include <iostream>
#include <string>

using namespace std;

class StudentRec
{
public:
    StudentRec();

    StudentRec(string initLastName, int studGrade);

    string GetLastName();

    int GetGrades(int gradeNum);

    void AddGrades(int studGrade);

private:
    static const int numGrades=10;
    static int gradeCounter;
    string lastName;
    int grades[numGrades];
};

#endif

In the Main.cpp file, I get an error I can t find the solution for. It reads error: "UserInterface" was not declared in this scope. I got this error while compiling in XCode I got error C3861: UserInterface : identifier not found

显然,在两个教育学院里,我还有学生注册和毕业会,但并不肯定你们需要。 事先获得帮助

最佳回答

看来UserInterface()实际上是GradeBook的成员功能正确?

如有必要,请在<代码>中添加关于成员职能的宣言。 GradeBook 声明:

class GradeBook
{
public:
    GradeBook();
    GradeBook(string initLastName, int studGrades);
    void AddStudent(string initLastName, int studGrades);
    void ShowStudents();

    void UserInterface(); // Added

    // ...
private:
    // ...
};

这样,汇编者将“知道”)作为成员职能存在。 您随后在<代码>中提供了定义,避免了GradeBook:UserInterface(,载于.cpp

然后,请在<代码>GradeBook上登出,例如<编码> /Book在<代码>main(<>功能>上的变量:

int main()
{
    GradeBook gradeBook;
    // This calls the member function UserInterface() on the gradeBook variable.
    gradeBook.UserInterface();
    // This calls the global UserInterface(), which doesn t exist.
    // UserInterface();
    return 0;
}
问题回答

<代码>UserInterface(>为GradeBook。 这一呼吁可能需要:

gradeBook.UserInterface();




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签