HelloWorld_java_ 2022-03-28 21:25 采纳率: 88.2%
浏览 164
已结题

C2352 “user::getdata”: 非静态成员函数的非法调用和E0254 不允许使用类型名的问题

想在function.cpp中创建一个类数组来接收user.cpp读出的文件,但是一直报错,那位可以解决一下

#pragma once
#include<iostream>
using namespace std;
#include"user.cpp"
#include<fstream>
#include<conio.h>
#include<string>
#define file "user.txt"
class function {
public:
    function() {

    }

    void adduser() {//开户
        
        fstream fs;
        int numuser = 0;
        fs.open(file, ios::in);
        while ( fs>>id && fs >> Name && fs >> password && fs>>Money && fs>>State ){
            ++numuser;

        }
        cout << "总人数为" << numuser<<endl;
        fs.close();
        fs.open(file, ios::app | ios::out);
    
        cout << "你的账号为:" << Id + numuser << endl;
        cout << "请输入姓名" << endl;
        cin >> Name;
        string Password1;
        string Password2;


        cout << "请输入长度50以内的密码并按回车键确定" << endl;
        //密码输入

        char ch;
        while ((ch = _getch()) != 13)

        {
            Password1 += ch;
            cout << "*";


        }
        cout << endl << "请再次输入以确定密码并按回车键确定" << endl;
        while ((ch = _getch()) != 13)

        {
            Password2 += ch;
            cout << "*";


        }
        if (Password2 == Password1) {
            cout << "密码正确" << endl;
        }
        else {
            cout << "密码错误" << endl;
            system("pause");

        }
        cout << "输入充值的金额" << endl;
        cin >> Money;
        fs << Id + numuser << "  "//账号
            << Name << "  " //姓名
            << Password2 << "  "//密码
            << Money << "  "//余额
            << State << endl;//状态
        fs.close();
    }
    void frozen() {
        cout << "请输入需要挂失的账号:"<<endl;
        int account;
        cin >> account;
        function** cgstate = user.getdata(account);//报错的地方,,,
        

    }
    string Name;
    int Id = 10000;
    int  id;
    int Money = 0;
    int State = 1;
    string password;
};

#pragma once
#include<iostream>
using namespace std;
#include<string>
#define file "user.txt"
#include<fstream>
class user {
    friend class function;
public:
    user( int id, string name, string password, int money,int State) {
        this->Name = name;
        this->id = id;
        this->Password = password;
        this->State = State;
    }
    user** getdata(int account) {//获取文档信息
        fstream ofs;
        int i = 0;
        int nume = 0;
        ofs.open(file, ios::in);
        while (ofs >> id && ofs >> Name && ofs >> Password && ofs >> money && ofs >> State) {
            nume++;//总人数 
        }
        arry[nume];
        while (ofs >>id && ofs >> Name && ofs >>Password && ofs >> money && ofs >> State) {
            user* User = NULL;
            User = new user(id, Name, Password, money, State);
            arry[i] = User;
            i++;
        }
        

        ofs.close();
        return  arry;
    }

    string Name;
    int id;
    string Password;
    int money;
    int State;
    user* arry[];
    ~user() {
        delete this->arry;
        
    }
};

  • 写回答

1条回答 默认 最新

  • bostonAlen 2022-03-28 21:47
    关注
    
    user u1(1,"zhangsan","password",100,0);
    user** cgstate = u1.getdata(account);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 4月6日
  • 已采纳回答 3月29日
  • 创建了问题 3月28日

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效