注册 登录
编程论坛 VC++/MFC

调用函数的时候出现错误,怎修改,还有应该注意的方面

yang20110816 发布于 2011-05-15 15:28, 358 次点击
#include <iostream>
using namespace std;

class Employee{
public:
    void setName(char name[30],char city[50],int postcode[10]){
        cout<<"input the name:"<<endl;
        cin.getline(name,30);
        cout<<"input the city"<<endl;
        cin.getline(city,50);
        cout<<"input the postcode:"<<endl;
        for(int i=0;i<10;i++){
            cin>>postcode[10];};
    }
     void diaplay(){
            cout<<"name:"<<name;
            cout<<"city:"<<city;
            cout<<"postcode:"<<postcode;
        }
private:
    char name[30];
    char city[50];
    int postcode[10];
    };



    void Employee::setName(char name[30],char city[50],int postcode[10]);
    void Employee::diaplay ();


    void main(){
        
        Employee  p;
        p.setName ();
        p.diaplay ();
        cout<<endl;

}

    Compiling...
jfh.cpp
C:\Program Files\VC++\MyProjects\brt\jfh.cpp(35) : error C2660: 'setName' : function does not take 0 parameters
执行 cl.exe 时出错.

jfh.obj - 1 error(s), 0 warning(s)
3 回复
#2
yuccn2011-05-15 18:29
p.setName ();这个函数没有传参数啊,加上参数就行了。
#3
yang201108162011-05-17 00:03
回复 2楼 yuccn
举个例子!
#4
zhoufeng19882011-05-17 11:16
程序代码:
char szName[100];
char szCity[50];
int  szPostCode[10];

Emploee p;
p.setName(szName, szCity, szPostCode);
试试
1