基于对象的编程风格 4.1 如何实现一个class 1 前置声明使我们得以进行类指针(class pointer)的定义,或以此class作为数据类型. 2 private members 只能在member function或是class friend内被取用.
基于12个网页-相关网页
如果我有一个对象的指针,转换到它的基类指针对象上,我能通过基类指针调用合适的成员函数。
If I have a pointer to an object cast to one of its base classes, I can call the correct member functions through the abstract base class.
对于类对象包含指针的情况下,我们要编写自己的拷贝构造函数,这样可以防止上述情况的发生。
For a situation where an object contain Pointers we have to write our own copy constructor that will prevent situations like those mentioned above.
与可怕的空指针异常(该异常除了报告空指针之外,对于将要发生的事情什么也不说)不同,类强制转换异常相对来说容易调试。
Unlike the dreaded null-pointer exception (which says nothing about what was expected to occur instead of the null pointer), a class-cast exception is relatively easy to debug.
Once I've got that, I can now start giving some variable names, sorry not, rephrase that, I can give some attributes, I can give some characteristics to these classes.
还有个指向内存中地址的指针,我还可以命名这个指针,因此cp1和cp2都是,指向它们的指针,一旦我创建了它类,我就可以开始赋予。
应用推荐