记:应聘中望龙腾软件 C++工程师

一面

1.问了项目的问题
2.const 修饰指针:const在星号左边,被指物是常量,const出现在星号右边,指针是常量。
3.堆和栈的生长方向:堆是由低到高,栈是由高到低。这个博文说的很清楚这样的设置方法可以充分的利用内存的空闲区域。
4.const关键字修饰类的成员函数的问题。

/*
验证const成员函数的性质。
1.const对象调用const成员函数,而不能调用非const成员函数。
2.有const修饰的成员函数,只能读取数据成员,而不能写数据成员。
3.非const对象可以调用const成员函数,也可以调用非const成员函数。默认调用的是非const成员函数。
4.const成员函数可以访问非const对象内的所有数据成员,也可以访问const对象内的所有数据成员。
5.非const成员函数只可以访问非const对象的任意的数据成员。
*/

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
//class A
//{
//public:
//    void f()
//    {
//        cout << "non const" << endl;
//    }
//    void f() const
//    {
//        cout << " const" << endl;
//    }
//};
//
//int main(int argc, char** argv)
//{
//    A a;
//    a.f();  //non const 因为a本身是非const的。调用的是非const成员函数。
//    const A& b = a;
//    b.f();  //b是a的别名。a是const的。输出是const
//    const A* c = &a;
//    c->f();  //c是指向a的指针,a是const的。输出是const
//    A* const d = &a;
//    d->f(); //指针d是常量,d指向的a不是常量。  输出是non const
//    A* const e = d;
//    e->f();  //同上,输出是non const.
//    const A* f = c;
//    f->f();   //输出是const
//    return 0;
//}

class Date
{
public:
	Date(int year, int month, int day):_year(year), _month(month), _day(day){}
	void Display1()
	{
		cout << _year << "-" << _month << "-" << _day << endl;
	}
	void Display2() const
	{
		cout << _year << "-" << _month << "-" << _day << endl;
	}
private:
	int _year;
	int _month;
	int _day;
};

int main()
{
	Date d1(2018, 1, 1);
	d1.Display1();    //非const对象,调用非const成员函数
	d1.Display2();    //非const对象,调用const成员函数
	const Date d2(2018, 1, 1);
	//d2.Display1();   //const对象,不能调用非const成员函数
	d2.Display2();     //const对象,可以调用const成员函数
	return 0;
}

5.static关键字修饰类的成员的问题。
6.mfc的问题。这个,以后再说吧。

凉了。

原创文章 77 获赞 4 访问量 9029

猜你喜欢

转载自blog.csdn.net/weixin_40007143/article/details/105215321
今日推荐