.用于访问成员对象
->用于访问成员对象指针
main.cpp
#include <iostream>
#include "score.h"
using namespace std;
int main()
{
score m;
score *p = new score;
m.set_name("xiaoming");
m.set_age(5);
p->set_name("limign");
p->set_age(5);
cout << m.get_name() << endl;
cout << m.get_age() << endl;
cout << p->get_name() << endl;
cout << p->get_age() << endl;
system("pause");
return 0;
}
score.h
#pragma once
#define _CRT_SECURE_NO_WARNINGS
class score
{
private:
char name[100];
int age;
public:
score();
~score();
void set_name(const char *s);
void set_age(const int i);
const char *get_name() const;
const int get_age() const;
};
score.cpp
#include "score.h"
#include <string.h>
score::score()
{
}
score::~score()
{
}
void score::set_name(const char *s)
{
strcpy(this->name, s);
}
void score::set_age(const int i)
{
this->age = i;
}
const char *score::get_name() const
{
return name;
}
const int score::get_age() const
{
return age;
}