0、vc++6.0 工程---win32控制台程序            文件---c++

1、建立结构体

 #include <iostream.h>
struct Point
{ int x;
int y;
}; void main ()
{
Point pt;
pt.x=;
pt.y=;
//cout << pt.x << endl << pt.y << endl; }
 

2、在结构体中,建立方法函数输出,主函数调用

 #include <iostream.h>
struct Point
{
public:
int x;
int y;
void output ()
{
cout << x << endl << y << endl;
}
}; void main ()
{
Point pt;
pt.x=;
pt.y=;
//cout << pt.x << endl << pt.y << endl;
pt.output(); }

3,struct 于 class 是一样的:  区别---struct默认都为public  class都为privit

sttuct在c++中同用

 #include <iostream.h>
//struct Point
class Point
{
public:
int x;
int y;
void output ()
{
cout << x << endl << y << endl;
}
}; void main ()
{
Point pt;
pt.x=;
pt.y=;
//cout << pt.x << endl << pt.y << endl;
pt.output(); }

4,类:有类似功能的整体,,,对像:整体中的个体

观念的转变:过程--对象

做一个方法--开车

过程:参数传递进来

对象:把汽车启动 设置为汽车的属性  ---只要调用汽车就可以开走了

收音机:打开-听

过程:调节音量函数--收音机是参数,(先做方法-后对操作对象)

对象:收音机类---里面对象--开---调节音量  (直接来操作类--里面包含)

5、初始化--不初始化 会输出随机数

未初始化

 #include <iostream.h>
class Point
{
public:
int x;
int y;
void output ()
{
cout << x << endl << y << endl;
}
}; void main ()
{
Point pt;
//pt.x=5;
//pt.y=5;
//cout << pt.x << endl << pt.y << endl;
pt.output(); }

初始化后----init是方法---point是对象  对象包含实现的方法

C过程:先方法 函数---传递参数 -对象 来实现

 #include <iostream.h>
class Point
{
public:
int x;
int y;
void init()
{
x=;
y=;
}
void output ()
{
cout << x << endl << y << endl;
}
}; void main ()
{
Point pt;
//pt.x=5;
//pt.y=5;
//cout << pt.x << endl << pt.y << endl;
pt.init();
pt.output(); }

6、构造函数--内存创建分配 ---帮助完成初始化(定义对象时,自动进行初始化)
    1)初始化

  2)创建对象本身--分配内存

每个类必须有一个构造函数,若果没有就不能创建类----(如果没有构造函数C++编译器会  自动创建变量,但是不能够赋初值)

3)如果定义了一个构造函数,编译器不再提供

 #include <iostream.h>
class Point
{
public:
int x;
int y;
Point()
{
x=;
y=;
}
void output ()
{
cout << x << endl << y << endl;
}
}; void main ()
{
Point pt;
//pt.x=5;
//pt.y=5;
//cout << pt.x << endl << pt.y << endl;
//pt.init();
pt.output(); }

7、析构函数----内存释放回收

  1)一个对象生命周期结束时,回收空间

  2)析构函数不能有返回值

  3)只能有一个析构该函数

  4)释放堆内存

 #include <iostream.h>
class Point
{
public:
int x;
int y;
Point()
{
x=;
y=;
}
~Point()
{ }
void output ()
{
cout << x << endl << y << endl;
}
}; void main ()
{
Point pt;
//pt.x=5;
//pt.y=5;
//cout << pt.x << endl << pt.y << endl;
//pt.init();
pt.output(); }

8、函数重载:两个构造函数--带参于不带参数同时存在
   更具不同参数 来选择 执行那个函数

   1)如   无参数输出为0    有参数输出为1

  

 #include <iostream.h>
class Point
{
public:
int x;
int y;
Point()
{
x=;
y=;
}
Point(int a, int b)
{
x=a;
y=b;
}
~Point()
{ }
void output ()
{
cout << x << endl << y << endl;
}
}; void main ()
{
Point pt(,);
//pt.x=5;
//pt.y=5;
//cout << pt.x << endl << pt.y << endl;
//pt.init();
pt.output(); }

  2)其他函数依然能构成函数的重载

条件:参数不同 或参数的个数不同

第一种:不行

    void output();

     int   output();

第二种:不行

    void output(int a,int b=0);

    void output(int a);

8、隐含指针

  1)隐含指针---代表指向本对象本身

  2)pt.output(5,5); 不接收到形参,还接收到了对象的地址,

  

下面输出的不是想要的 5 5 而是 3 3   原因是   变量 不可以见性 只能改变形参

 #include <iostream.h>
class Point
{
public:
int x;
int y;
Point()
{
x=;
y=;
}
Point(int a, int b)
{
x=a;
y=b;
}
~Point()
{ }
void output ()
{
cout << x << endl << y << endl;
}
void output (int x,int y)
{
x=x;
y=y;
}
}; void main ()
{
Point pt(,);
pt.output(,);
pt.output(); }

解决方法一、this->指针
  

 #include <iostream.h>
class Point
{
public:
int x;
int y;
Point()
{
x=;
y=;
}
Point(int a, int b)
{
x=a;
y=b;
}
~Point()
{ }
void output ()
{
cout << x << endl << y << endl;
}
void output (int x,int y)
{
this->x=x;
this->y=y;
}
}; void main ()
{
Point pt(,);
pt.output(,);
pt.output(); }

解决方法二、

 #include <iostream.h>
class Point
{
public:
int x;
int y;
Point()
{
x=;
y=;
}
Point(int a, int b)
{
x=a;
y=b;
}
~Point()
{ }
void output ()
{
cout << x << endl << y << endl;
}
void output (int c,int d)
{
x=c;
y=d;
}
/* void output (int x,int y)
{
this->x=x;
this->y=y;
}*/
}; void main ()
{
Point pt(,);
pt.output(,);
pt.output(); }

小技巧:
    

2.1孙鑫C++的更多相关文章

  1. 孙鑫VC学习笔记:多线程编程

    孙鑫VC学习笔记:多线程编程 SkySeraph Dec 11st 2010  HQU Email:zgzhaobo@gmail.com    QQ:452728574 Latest Modified ...

  2. 孙鑫视频学习:VS2010中找不到【Tab order】菜单项

    在学习孙鑫视频中,修改Tab顺序时,找不到VC6.0中提到的[Layout]->[Tab order]菜单项,但VC2010中可以用Ctrl+D调出来Tab顺序,或者[格式]->[Tab键 ...

  3. 孙鑫视频学习:改变窗口过程函数中出现error C2440错误的解决方法

    在Visual Studio 2010中,即使代码是完完全全按照孙鑫视频中的敲,也会在出现error C2440,这是因为开发平台由VC6.0升级至VS2010,需要将原有的项目迁移.VS2010对消 ...

  4. 孙鑫视频学习:关于Visual Studio 2010中MFC工程的消息WM_INITDIALOG找不到的问题

    学习孙鑫的那个深入详解C++视频时,有一处给编辑框空间改写窗口过程函数的例子,其中需要添加一个WM_INITDIALOG消息响应函数,但在类向导的消息栏下找不到WM_INITDIALOG消息.解决方法 ...

  5. 孙鑫VC++视频教程笔记

    写在前面的话:在学习孙鑫老师的VC++视频时,为了加深自己对知识的深入理解,就做了下面的笔记. 第一讲: 第二讲: 第三讲: 第四讲: 第五讲: 第六讲: 第七讲: 第八讲: 第九讲: 第十讲: 第十 ...

  6. 孙鑫视频VC++深入详解学习笔记

    孙鑫视频VC++深入详解学习笔记 VC++深入详解学习笔记 Lesson1: Windows程序运行原理及程序编写流程 Lesson2: 掌握C++基本语法 Lesson3: MFC框架程序剖析 Le ...

  7. 孙鑫VC++视频教程(1-20课全)

    孙鑫VC++视频教程(1-20课全)PPT讲义和源代码 http://down.51cto.com/data/467760 孙鑫VC++从入门到精通开发详解视频教程[20讲] http://down. ...

  8. 孙鑫VC学习系列教程

    教程简介 1.循序渐进 从Win32SDK编程开始讲解,帮助大家理解掌握Windows编程的核心 -- 消息循环机制. 2.通俗易懂 编程语言枯燥难懂,然而通过孙鑫老师形象化的讲解,Windows和M ...

  9. 孙鑫C++教程留下来的作业--如何让工具栏在原来隐藏的位置出现

    --加油,不仅仅是口号! BEGIN---------------------------------- 将工具栏进行停靠.当隐藏后再次点击出现的时候它出现在工具栏顶部了,并没有停靠在原来的位置,如何 ...

  10. 孙鑫MFC学习笔记20:Hook编程

    1.HOOK拦截消息,设置越后的钩子优先级越高(钩子队列)2.SetWindowHookEx设置钩子    如果thread identifier为0或其他进程创建的线程,回调函数需要在动态链接库中声 ...

随机推荐

  1. centos7 docker1.12 私有仓库

    docker1.12私有仓库 参考:http://www.cnblogs.com/xcloudbiz/articles/5497037.html 参考:http://www.07net01.com/2 ...

  2. 【Python】django权限管理

    参考:http://www.cnblogs.com/esperyong/ 参考:https://docs.djangoproject.com/en/1.8/topics/auth/default/#t ...

  3. c# winform 关于DataGridView的一些操作(很全,绝对够用)

    转自:http://heisetoufa.iteye.com/blog/405317 设置字段名 设置字段值 设定单元格表示 Error图标 设定当前单元格 取得当前单元格内容 取得当前单元格的列 I ...

  4. linux tcp状态学习

    参考: http://huoding.com/2013/12/31/316 http://www.cnblogs.com/sunxucool/p/3449068.html http://maoyida ...

  5. 轻松入门React和Webpack

    最近在学习React.js,之前都是直接用最原生的方式去写React代码,发现组织起来特别麻烦,之前听人说用Webpack组织React组件得心应手,就花了点时间学习了一下,收获颇丰 <!-- ...

  6. 你真的理解z-index吗?

    一.前言 假如只是开发简单的弹窗效果,懂得通过z-index来调整元素间的层叠关系就够了.但要将多个弹窗间层叠关系给处理好,那么充分理解z-index背后的原理及兼容性问题就是必要的知识储备了.本文作 ...

  7. php+mysql简单留言,适合新手

    <html> <head> <title> php留言板 </title> <style> p,textarea{vertical-alig ...

  8. Android开发教程AnimationDrawable逐帧播放动画

    下面我们一起来看篇Android开发AnimationDrawable控制逐帧播放动画实现过程,希望文章对各位朋友带不一些帮助. 当我们点击按钮时,该图片会不停的旋转,当再次点击按钮时,会停止在当前的 ...

  9. Spring web Flow2学习笔记

    想抽时间研究一下Spring web Flow2,能够找到的唯一电子书是<深入解析Spring+MVC与Web Flow>,我现在摘录本书的一段内容如下,通过这一段,大家可以想象中文背景的 ...

  10. grep命令实战

    显示/etc/rc.d/rc.sysinit中以#开头,且后面跟一个或多个空白字符,而后又跟了任意非空白字符的行 grep "^#[[:space:]]\+.\+" /etc/rc ...