帮小弟看下c++指针访问成员函数的错误吧
#include<iostream.h>
class AnotherDate{
private:
int year;
int month;
int day;
public:
void setDate(int y,int m,int d){
year=y;
month=m;
day=d;
}
int isLeapYear(){
return (year%4==0&&year%100!=0)||(year%400==0);
}
void print(){
cout<<"year:"<<year<<",month:"<<month<<",day:"<<day<<endl;
}
};
void main(){
AnotherDate *date;
date->setDate(1980,3,1);
date->print();
}
编译能通过,但就是运行不起来,不知道怎么回事,希望大家帮帮我,多谢拉
class AnotherDate{
private:
int year;
int month;
int day;
public:
void setDate(int y,int m,int d){
year=y;
month=m;
day=d;
}
int isLeapYear(){
return (year%4==0&&year%100!=0)||(year%400==0);
}
void print(){
cout<<"year:"<<year<<",month:"<<month<<",day:"<<day<<endl;
}
};
void main(){
AnotherDate *date;
date->setDate(1980,3,1);
date->print();
}
编译能通过,但就是运行不起来,不知道怎么回事,希望大家帮帮我,多谢拉
...全文
相关推荐
C++类的空指针调用成员函数的代码
主要介绍了C++类的空指针调用成员函数,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
C++中this指针的用法及介绍
this指针只能在一个类的成员函数中调用,它表示当前对象的地址。下面是一个例子: 代码如下: void Date::setMonth( int mn ) { month = mn; // 这三句是等价的 this->month = mn; (*this).month = mn; } 1. this只能在成员函数中使用。全局函数,静态函数都不能使用this。实际上,成员函数默认第一个参数为T* const register this。如: class A{public: int func(int p){}};其中,func的原型在编译器
空指针访问成员函数.zip
空指针访问成员函数
C++中this指针的用法
C++中this指针的用法C++中this指针的用法C++中this指针的用法C++中this指针的用法C++中this指针的用法C++中this指针的用法C++中this指针的用法C++中this指针的用法C++中this指针的用法
实例解析C++中类的成员函数指针
主要介绍了C++中类的成员函数指针,例子中以讨论用函数指针调用类的成员函数为主,需要的朋友可以参考下


新手乐园
