Youyinnn 2016-05-20 02:32 采纳率: 100%
浏览 3055
已采纳

c++的list能否在自定义类中使用

这是我的menusystem.h头文件,有的功能还没写完,我想在主菜单的b功能里面实现对这两个集合的遍历,我有另外两个头文件分别包含老师类和学生类。

list::iterator() its;
list::iterator() itt;
这两句会提示错误:
error C2146: syntax error : missing ';' before identifier 'its'
error C2501: 'its' : missing storage-class or type specifiers
error C2146: syntax error : missing ';' before identifier 'itt'
error C2535: 'int __thiscall MenuSystem::iterator(void)' : member function already defined or declaredd:\vc6.0(绿色win8可用)\program ide\vc++6.0\myprojects\课程设计\menusystem.h(23) : see declaration of 'iterator'
error C2501: 'itt' : missing storage-class or type specifiers

/*

系统的核心类,通过该菜单系统实现所有功能,通过友元联系上老师类和学生类。

*/
#pragma once
#ifndef MENUSYSTEM_H
#define MENUSYSTEM_H
#include
#include

#include"student.h"
#include"teacher.h"
class Teacher;
class Student;
class SchoolPerson;
using namespace std;
class MenuSystem
{
public:
typedef list LISTS;
typedef list LISTT;
LISTS lists;
LISTT listt;
void showmenu()
{

    list<Student>::iterator() its;
    list<Teacher>::iterator() itt;
    cout<<"欢迎进入高校水电管理系统"<<endl;
    START:
    cout<<"请选择功能(输入数字):"<<endl;
    cout<<"a、录入用户信息"<<endl;
    cout<<"b、查询用户信息"<<endl;
    cout<<"c、查询未缴费名单"<<endl;
    cout<<"d、退出系统"<<endl;
    cin>>button;
    switch (button)
    {
        case 'a':
            cout<<"用户信息录入界面";
            cout<<"请输入S或者T选择录入学生信息还是老师信息输入其他返回主界面:";
            cin>>career;
            switch (career)
            {
                case 'S':
                    {
                        int swi=1;
                        while (swi==1)
                        {
                            Student *stu;
                            stu=new Student;
                            (*stu).set();
                            lists.push_front(*stu);
                            cout<<"输入1继续添加,输入其他退出添加。";
                            cin>>swi;
                        }
                    }
                    break;
                case 'T':
                    {
                        int swi=1;
                        while (swi==1)
                        {
                            Teacher *tea;
                            tea=new Teacher;
                            (*tea).set();
                            listt.push_front(*tea);
                            cout<<"输入1继续添加,输入其他退出添加。";
                            cin>>swi;
                        }
                    }
                    break;
                default:
                    goto START;
            }
            break;
        case 'b':
            {
                char button2;
                cout<<"用户信息查询"<<endl;
                cout<<"a、查询所有学生信息"<<endl;
                cout<<"b、查询所以老师信息"<<endl;
                cout<<"c、查询学生个人信息"<<endl;
                cout<<"d、查询老师个人信息"<<endl;
                cout<<"按其他键返回主菜单"<<endl;
                cin>>button2;
                switch (button2)
                {
                    case 'a':
                        {
                            for (its=lists.begin();its!=lists.end();its++)
                            {
                                (*its).print_information();
                                cout<<endl;
                            }
                        }
                    break;

                    case 'b':
                        {
                            for (itt=listt.begin();itt!=lists.end();itt++)
                            {
                                (*itt).print_information();
                                cout<<endl;
                            }
                        }
                    break;

                    case 'c':
                        {
                            int sign=0;
                            long snumber;
                            cout<<"请输入要查询的学生的学号:";
                            cin>>snumber;
                            for (its=lists.begin();its!=lists.end();its++)
                            {
                                if ((*its).getnumber()==snumber)
                                {
                                    cout<<"查询结果如下:"<<endl;
                                    (*its).print_information();
                                    sign=1;
                                }
                            }
                            if (sign==0)
                                cout<<"没有此用户!";
                        }
                    break;

                    case 'd':
                        {
                            int sign=0;
                            long tnumber;
                            cout<<"请输入要查询的老师的工号:";
                            cin>>snumber;
                            for (itt=lists.begin();itts!=listt.end();itt++)
                            {
                                if ((*itt).getnumber()==tnumber)
                                {
                                    cout<<"查询结果如下:"<<endl;
                                    (*itt).print_information();
                                    sign=1;
                                }
                            }
                            if (sign==0)
                                cout<<"没有此用户!";
                        }
                        break;
                    default:
                        goto START;
                }
            }
        case 'c':
            //调用没交费学生信息
            //调用没交费老师信息
            break;
        case 'd':
            exit(0);
        default:
            cout<<"错误的指令,请重新输入:"<<endl;
            goto START;
    }
}

private:
char button;
char career;
};
#endif

  • 写回答

1条回答 默认 最新

  • 小灸舞 2016-05-20 03:38
    关注

    list::iterator() its;
    list::iterator() itt;
    去掉括号。改为:

     list<Student>::iterator its;
     list<Teacher>::iterator itt;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥85 maple软件,solve求反函数,出现rootof怎么办?
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题