课程笔记
爱吃的小花猫
来者皆客
展开
-
software testing
Software TestingSoftware testing is the process of evaluation a software item to detect differences between given input and expected output. Also to assess the feature of A software item. Testing as...原创 2015-06-14 12:39:44 · 1056 阅读 · 0 评论 -
在一个类的成员函数中调用另一个类的成员函数
假设你想在类A里调用类B的函数int f(x),两种办法:1、class A::B 也就是说将B定义为A的父类, 这样你就可以自然的在A里面用f(x)了2、class A{B B_ins;int g(x);}int g(x){return B_ins.f(x)}也就是说你可以在A里面使用一个B的对象作为成员变量,这样就可以用他的函数了原创 2015-03-23 13:14:41 · 11536 阅读 · 0 评论 -
什么是类的成员函数和非成员函数
类有成员变量和成员函数。而函数中,不是任何一个类的成员的函数,就是非成员函数。例如:class A{public: void f1(){}; // 这个就是成员函数。 void f2(); // 这个也是成员函数声明,其实现在类的外部。};void A::f2(){} // 这个是成员函数的实现。void f3(){}; //原创 2015-03-23 13:10:38 · 6402 阅读 · 0 评论 -
Class example in C/C++
class Player { private: int health; //these are the attributes int strength; int agility; public:void move();void attackEnemy(); //these are the method prototypesvoid getTre原创 2015-03-18 05:48:42 · 1037 阅读 · 0 评论 -
C++中析构函数的作用
如果构造函数打开了一个文件,最后不需要使用时文件就要被关闭。析构函数允许类自动完成类似清理工作,不必调用其他成员函数。析构函数也是特殊的类成员函数。简单来说,析构函数与构造函数的作用正好相反,它用来完成对象被删除前的一些清理工作,也就是专门的扫尾工作。原创 2015-03-23 14:04:59 · 3130 阅读 · 0 评论 -
子类的拷贝构造函数如何调用其父类的拷贝构造函数
class base {public: base(int initialvalue = 0): x(initialvalue) {} base(const base& rhs): x(rhs.x) {}private: int x;};class derived: public base {public: derived(int init原创 2015-03-23 13:32:10 · 4144 阅读 · 0 评论 -
更多的C++的class的例子
class A{ public: A(){}//构造函数,作用分配类所需的空间};int main(){ A a;}a就是类A的实例!原创 2015-03-14 18:22:18 · 652 阅读 · 0 评论 -
什么是类的实例
定义的类的对象比如你定义了类如下:class A{public://成员函数private://成员变量};而 A a; //就表示你定义了一个类A的实例,其实,和定义普通类型变量相似,只不过这里的类型换成了类A,而不是像整型等基本类型,可以如同:int i; 一样去理解,i 就相当于int类型的实例。这时和struct一样原创 2015-03-14 18:41:13 · 3829 阅读 · 0 评论 -
C++中的class (2)
class Father{ protected void methodA(){ //do something } private void methodB(){//do something }}class Child:Father{}那么Child child=new Child();child.methodA(); //Rightchild.methodB原创 2015-03-14 03:33:59 · 623 阅读 · 0 评论 -
C#中构造函数的定义
C#构造函数是在创建给定类型的对象时执行的类方法。构造函数具有与类相同的名称,它通常初始化新对象的数据成员。不带参数的构造函数称为“默认构造函数”。 无论何时,只要使用 new 运算符实例化对象,并且不为 new 提供任何参数,就会调用默认构造函数。除非类是 static 的,否则 C# 编译器将为无构造函数的类提供一个公共的默认构造函数,以便该类可以实例化。构造函数必须是在类里的一级声明,并原创 2015-03-23 13:34:57 · 2086 阅读 · 0 评论 -
c++构造函数与析构函数
/*设计一个类,它具有一个float指针成员.构造函数具有一个整形参数count,它为指针成员分配count个存储数据的元素空间.析构函数释放指针指向的空间.另外设计2个函数成员完成如下功能: (1)向指针指向的空间中存储数据; (2)返回这些数的平均值.*/#includeclass FLOAT{ public: FLOAT(int count原创 2015-03-23 13:49:54 · 2259 阅读 · 0 评论 -
什么是类(class)成员函数
就是一个类(class)里面所定义的函数例如class A{public: void B();private: int C();protected: bool D(int i);};那么,B(),C(),D(int)都是A的成员函数原创 2015-03-23 13:06:44 · 2492 阅读 · 0 评论 -
保存对象到文件中
public static void writeObjectToFile(Object obj) { File file =new File("test.dat"); FileOutputStream out; try { out = new FileOutputStream(file);原创 2015-06-25 04:01:20 · 1001 阅读 · 0 评论 -
constructor C++ example
The constructor for this class could be defined, as usual, as: Rectangle::Rectangle (int x, int y) { width=x; height=y; } But it could also be defined using membe原创 2015-04-08 06:21:17 · 1282 阅读 · 0 评论 -
加拿大的考试季 帮助及讨论帖
多谢大家的一直以来的支持今日应该是加拿大、美国等国家期末考试的非常时期,所以我想尽量的帮助到大家,如果有什么问题的话,可以向给我评论,看我能不能帮到大家。我可以回答的问题不限,但我的时间有限,所以回答的速度不敢保证。多谢原创 2015-04-08 08:07:59 · 860 阅读 · 1 评论 -
class example of C++
#include using namespace std;class Rectangle { int width, height; public: void set_values (int,int); int area() {return width*height;}};void Rectangle::set_values (int x,原创 2015-04-08 05:49:29 · 1516 阅读 · 0 评论 -
构造函数与其他类方法的区别
区别:1、构造函数的函数名称与类名同名,其他方法(函数)名称可以自定义。2、构造函数仅在对象被创建时系统会根据给定的参数以及类中的构造函数定义进行选择调用,如果类中没有定义构造函数,系统默认会提供一个无参构造空函数,什么都不会做,只是满足接口要求,构造函数不能被显式调用。其他函数根据程序员需要而调用,且必须显式调用。3、由于对象创建后,系统必须返回新建对象的地址,赋值给指针变量(C++原创 2015-04-04 12:49:54 · 2919 阅读 · 0 评论 -
constructors and destructors
A constructor is a method that gets called immediately when an object is allocated (on the stack or the heap).It is the constructor’s job to initialize the object’s attributes to sensible initial va原创 2015-03-18 06:23:35 · 1106 阅读 · 0 评论 -
析构函数允许重载吗?
不能,因为无参无返回值无类型原创 2015-03-23 14:08:31 · 4488 阅读 · 0 评论 -
Creating objects on stack or heap
class Player { private:int health; int strength; int agility;public:void move();void attackEnemy(); void getTreasure();};int main(){Player p1;Player *p2 = new Playe原创 2015-03-18 06:33:40 · 992 阅读 · 1 评论 -
C++ classes and uniform initialization
// classes and uniform initialization#include using namespace std;class Circle { double radius; public: Circle(double r) { radius = r; } double circum() {return 2*radius*3.141592原创 2015-03-18 02:50:04 · 629 阅读 · 0 评论 -
programming error (function overloading)
Here is the definition of function overloading:Function overloading or meth overloading is the ability to create multiple methods of same name with different implementations:Here is an exa原创 2015-03-18 02:41:37 · 830 阅读 · 0 评论 -
C++中的class (1)
1、public:public表明该数据成员、成员函数是对所有用户开放的,所有用户都可以直接进行调用2、private:private表示私有,私有的意思就是除了class自己之外,任何人都不可以直接使用,私有财产神圣不可侵犯嘛,即便是子女,朋友,都不可以使用。 3、protected:protected对于子女、朋友来说,就是public的,可以自由使用,没有任何限制,而原创 2015-03-14 03:04:14 · 752 阅读 · 0 评论 -
C++的class的例子
私有就是只能够通过内部调用,在类外面是不可以使用私有成员的简单的写一个 Class A{ public: //你可以通过公有的函数去访问私有成员 Demo() //可以在这使用私有成员 { m_buff = 0; } private: //私有成员 int m_buff;}void main(){ A a原创 2015-03-14 18:04:53 · 893 阅读 · 0 评论 -
Class 找出一个整形数组中的元素的最大值
目的:找出一个整形数组中的元素的最大值 下面,我们用类和对象的方法来做。 #include using namespace std; class Array_max{ private://声明在类的外部不可访问的隐私成员 int array[10]; int max; public://声明在原创 2015-03-14 19:43:56 · 5357 阅读 · 0 评论 -
struct 和 class 不同点
在 C++ 里面 struct 和 class 没有本质的区别只是成员和继承方式的默认不同struct 是 publicclass 是 private我的个人建议是只要需要实现成员函数的就用 class至于效率问题,那得看什么特性好多都是编译时就处理掉的事情,比如普通的函数重载(非 virtual 成员函数),比如模板,只是增加编译时间而已,对运行效率没影响原创 2015-03-13 12:41:21 · 7832 阅读 · 1 评论 -
一个关于Class的小点
public 是公有private 是私有没有写就是private原创 2015-03-13 12:28:28 · 610 阅读 · 0 评论 -
C++中的class
C++中的class是C++不同于C的关键所在;是面向对象中声明的类; 公有成员public member 在程序的任何地方都可以被访问实行信息隐藏的类将 其public 成员限制在成员函数上这种函数定义了可以被一般程序用来操纵该类类型对象的操作 私有成员private member原创 2015-03-13 11:24:52 · 51150 阅读 · 0 评论 -
OOP的基本原则(转自博客园)
面向对象的原则头五项原则是关于类设计的,它们是:SRP,单一职责原则,一个类应该有且只有一个改变的理由。OCP,开放封闭原则,你应该能够不用修改原有类就能扩展一个类的行为。LSP,Liskov替换原则,派生类要与其基类自相容。DIP,依赖倒置原则,依赖于抽象而不是实现。ISP,接口隔离原则,客户只要关注它们所需的接口。另外的六项是关于包的设计原则。在本文中,包是指一个二进制原创 2015-03-16 13:47:14 · 1855 阅读 · 0 评论 -
C++中public、protected及private用法(From MSDN)
public(C# 参考): https://msdn.microsoft.com/zh-cn/library/yzh058ae.aspxprotected(C# 参考):https://msdn.microsoft.com/zh-cn/library/bcd5672a.aspxprivate(C# 参考):https://msdn.micros原创 2015-03-13 13:44:43 · 731 阅读 · 0 评论 -
C++类和对象的一个简单的实例
#include usingnamespace std; classArray_max{ private://声明在类的外部不可访问的隐私成员 intarray[10]; intmax; public://声明在类的外部可以访问的开放的成员函数原创 2015-03-14 19:48:37 · 903 阅读 · 0 评论 -
OOP Class详解
对象[编辑]对象(Object)是类的实例。例如,“狗”这个类列举狗的特点,从而使这个类定义了世界上所有的狗。而莱丝这个对象则是一条具体的狗,它的属性也是具体的。狗有皮毛颜色,而莱丝的皮毛颜色是棕白色的。因此,莱丝就是狗这个类的一个实例。一个具体对象属性的值被称作它的“状态”。(系统给对象分配内存空间,而不会给类分配内存空间。这很好理解,类是抽象的系统不可能给抽象的东西分配空间,而对象则是转载 2015-03-16 14:05:37 · 2021 阅读 · 0 评论 -
面向对象程序设计的思想
首先,我们会认为系统中一切皆为对象对象是属性及其操作的封装体;同时对象可按其性质划分为类举个例子:一个游戏的人物,人物有一把刀,人和刀都是实物所以说两个关系就是对象。那么属性就是人本身的攻击值,和刀的攻击值。 对象里面定义的那些变量称之为属性,属性实际的值标识着对象本身的状态,行为是指对象的方法。一般情况下行为会影响属性,属性不原创 2015-03-16 14:27:18 · 1622 阅读 · 0 评论 -
Class 与 new的配合使用
class Type{ // 定义新的类型Type/// ......};Type a; Type b; // 像int a; int b;那样使用, 定义a和b为Type类型的变量int* p = new int; // 分配一个int大小的内存int* pp = new int[100] // 分配100个int的内存Type* pt =原创 2015-03-13 12:46:18 · 6828 阅读 · 0 评论 -
Pointers to classes (From the note of my firend)
Pointers to classesObjects can also be pointed to by pointers: Once declared, a class becomes a valid type, so it can be used as the type pointed to by a pointer. For example:原创 2015-03-18 01:49:25 · 1069 阅读 · 1 评论 -
C++ overloading contructor
// overloading class constructors#include using namespace std;class Rectangle { int width, height; public: Rectangle (); Rectangle (int,int); int area (void) {return (width*h原创 2015-03-18 02:48:57 · 830 阅读 · 0 评论 -
Class (example in cplusplus.com)
Classes Classes are an expanded concept of data structures: like data structures, they can contain data members, but they can also contain functions as members.An object is an instantiation原创 2015-03-18 01:30:40 · 554 阅读 · 0 评论 -
Class C++
为了尽量减少全局变量的使用并提供用户自定义类型的功能,C++语言提供了一种新的语言机制---类(class),并以类作为构造程序的基本单位#includeusing namespace std;class C{public:int getAge()const{return age;};void setAge(int n){age=n;}原创 2015-03-17 11:18:26 · 1036 阅读 · 1 评论 -
C++继承经典例子
c++继承经典例子#include class Base{private: int b_number;public: Base( ){} Base(int i) : b_number (i) { } int get_number( ) {return b_number;} void p原创 2015-03-17 08:33:14 · 3277 阅读 · 1 评论 -
Struct和Class的区别
C++中的struct对C中的struct进行了扩充,它已经不再只是一个包含不同数据类型的数据结构了,它已经获取了太多的功能。struct能包含成员函数吗? 能!struct能继承吗? 能!!struct能实现多态吗? 能!!! 既然这些它都能实现,那它和class还能有什么区别?最本质的一个区别就是默认的访问控制: 默认的继承访问权限struct是pu转载 2015-03-17 11:49:27 · 1594 阅读 · 0 评论