在:http://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/C++ - 類問題
有以下程序(我做了一些小的修改):
#include <iostream>
class Employee
{
public:
char m_strName[25];
int m_id;
double m_wage;
//set the employee information
void setInfo(char *strName,int id,double wage)
{
strncpy(m_strName,strName,25);
m_id=id;
m_wage=wage;
}
//print employee information to the screen
void print()
{
std::cout<<"Name: "<<m_strName<<"id: "<<m_id<<"wage: $"<<wage<<std::endl;
}
};
int main()
{
//declare employee
Employee abder;
abder.setInfo("Abder-Rahman",123,400);
abder.print();
return 0;
}
當我嘗試編譯它,我得到如下:
而且,爲什麼在這裏使用了一個指針? void setInfo(char *strName,int id,double wage)
謝謝。
爲什麼沒有縮進? – 2011-01-22 14:22:19