当前位置: 首页 > news >正文

网站设计专业有前途吗郑州seo网站有优化

网站设计专业有前途吗,郑州seo网站有优化,如何编写网站建设销售的心得,seo优化方法网站快速排名推广渠道类的构造函数 类的构造函数是类的一种特殊的成员函数,它会在每次创建类的新对象时执行。 构造函数的名称与类的名称是完全相同的,并且不会返回任何类型,也不会返回 void。构造函数可用于为某些成员变量设置初始值。 下面的实例有助于更好地…

类的构造函数

类的构造函数是类的一种特殊的成员函数,它会在每次创建类的新对象时执行。

构造函数的名称与类的名称是完全相同的,并且不会返回任何类型,也不会返回 void。构造函数可用于为某些成员变量设置初始值。

下面的实例有助于更好地理解构造函数的概念:

#include <iostream>using namespace std;class Line
{public:void setLength( double len );double getLength( void );Line();  // 这是构造函数private:double length;
};// 成员函数定义,包括构造函数
Line::Line(void)
{cout << "Object is being created" << endl;
}void Line::setLength( double len )
{length = len;
}double Line::getLength( void )
{return length;
}
// 程序的主函数
int main( )
{Line line;// 设置长度line.setLength(6.0); cout << "Length of line : " << line.getLength() <<endl;return 0;
}

编译执行结果:

Object is being created
Length of line : 6

带参数的构造函数

默认的构造函数没有任何参数,但如果需要,构造函数也可以带有参数。这样在创建对象时就会给对象赋初始值,如下面的例子所示:

#include <iostream>using namespace std;class Line
{public:void setLength( double len );double getLength( void );Line(double len);  // 这是构造函数private:double length;
};// 成员函数定义,包括构造函数
Line::Line( double len)
{cout << "Object is being created, length = " << len << endl;length = len;
}void Line::setLength( double len )
{length = len;
}double Line::getLength( void )
{return length;
}
// 程序的主函数
int main( )
{Line line(10.0);// 获取默认设置的长度cout << "Length of line : " << line.getLength() <<endl;// 再次设置长度line.setLength(6.0); cout << "Length of line : " << line.getLength() <<endl;return 0;
}

编译执行结果:

Object is being created, length = 10
Length of line : 10
Length of line : 6

类对象初始化的时候加括号与不加括号有什么区别~

#include<iostream>
using namespace std;class A
{
public:A(){cout << "A()" << endl;}A(int a){cout << "A(int a)" << endl;}
};int main()
{//栈上//warning C4930 : “A a(void)” : 未调用原型函数(是否是有意用变量定义的 ? )A a();//这里声明了一个函数,没有传入的参数,返回值为类类型cout << "~~~~~~~~~~~" << endl;A b;//默认调用“对象名()”这个构造函数构造对象cout << "~~~~~~~~~~~" << endl;A c(1);//默认调用相应的构造函数构造对象//堆上,加括号不加括号无差别,都调用默认的构造函数A *d = new A();A *e = new A;//对于内置类型而言,加括号是进行了初始化,不加是未进行初始化int *f = new int();int *g = new int;cout << *f << endl;cout << *g << endl;system("pause");return 0;
}

linux不认识这 system(“pause”); 这个代码。

我们可以删掉这个端代码。也可以修改为 pause();fa267072492942ea9962785918ccaac2.png

使用初始化列表来初始化字段

使用初始化列表来初始化字段:

Line::Line( double len): length(len)
{cout << "Object is being created, length = " << len << endl;
}

上面的语法等同于如下语法:

Line::Line( double len)
{length = len;cout << "Object is being created, length = " << len << endl;
}

假设有一个类 C,具有多个字段 X、Y、Z 等需要进行初始化,同理地,您可以使用上面的语法,只需要在不同的字段使用逗号进行分隔,如下所示:

C::C( double a, double b, double c): X(a), Y(b), Z(c)
{....
}

类的析构函数

类的析构函数是类的一种特殊的成员函数,它会在每次删除所创建的对象时执行。

析构函数的名称与类的名称是完全相同的,只是在前面加了个波浪号(~)作为前缀,它不会返回任何值,也不能带有任何参数。析构函数有助于在跳出程序(比如关闭文件、释放内存等)前释放资源。

下面的实例有助于更好地理解析构函数的概念:

#include <iostream>using namespace std;class Line
{public:void setLength( double len );double getLength( void );Line();   // 这是构造函数声明~Line();  // 这是析构函数声明private:double length;
};// 成员函数定义,包括构造函数
Line::Line(void)
{cout << "Object is being created" << endl;
}
Line::~Line(void)
{cout << "Object is being deleted" << endl;
}void Line::setLength( double len )
{length = len;
}double Line::getLength( void )
{return length;
}
// 程序的主函数
int main( )
{Line line;// 设置长度line.setLength(6.0); cout << "Length of line : " << line.getLength() <<endl;return 0;
}

编译执行结果:

Object is being created
Length of line : 6
Object is being deleted

一个类内可以有多个构造函数,可以是一般类型的,也可以是带参数的,相当于重载构造函数,但是析构函数只能有一个

示例:

class Matrix
{
public:Matrix(int row, int col);                                            //普通构造函数Matrix(const Matrix& matrix);                                        //拷贝构造函数Matrix();                                                            //构造空矩阵的构造函数void print(void);~Matrix();
};

 

 


文章转载自:
http://ebulliency.zfyr.cn
http://madafu.zfyr.cn
http://lez.zfyr.cn
http://certification.zfyr.cn
http://evocable.zfyr.cn
http://piemonte.zfyr.cn
http://bridal.zfyr.cn
http://sandhog.zfyr.cn
http://hackmatack.zfyr.cn
http://continuity.zfyr.cn
http://bimillennial.zfyr.cn
http://selective.zfyr.cn
http://superactinide.zfyr.cn
http://vastly.zfyr.cn
http://shutter.zfyr.cn
http://plotting.zfyr.cn
http://hooky.zfyr.cn
http://kettledrummer.zfyr.cn
http://murk.zfyr.cn
http://hausa.zfyr.cn
http://gelsemium.zfyr.cn
http://equimultiple.zfyr.cn
http://babouche.zfyr.cn
http://calorification.zfyr.cn
http://downflow.zfyr.cn
http://nicker.zfyr.cn
http://evil.zfyr.cn
http://nimes.zfyr.cn
http://krypton.zfyr.cn
http://sustentation.zfyr.cn
http://predominant.zfyr.cn
http://forasmuch.zfyr.cn
http://vitoria.zfyr.cn
http://prig.zfyr.cn
http://burst.zfyr.cn
http://gustavian.zfyr.cn
http://bodacious.zfyr.cn
http://colourful.zfyr.cn
http://gotha.zfyr.cn
http://cellar.zfyr.cn
http://luminescent.zfyr.cn
http://cifs.zfyr.cn
http://corban.zfyr.cn
http://dieb.zfyr.cn
http://argentite.zfyr.cn
http://et.zfyr.cn
http://beautify.zfyr.cn
http://sardonic.zfyr.cn
http://rubefacient.zfyr.cn
http://pistache.zfyr.cn
http://newsbeat.zfyr.cn
http://lenticel.zfyr.cn
http://bricklaying.zfyr.cn
http://lee.zfyr.cn
http://lanthanide.zfyr.cn
http://deknight.zfyr.cn
http://coinstitutional.zfyr.cn
http://flic.zfyr.cn
http://missilery.zfyr.cn
http://feuilleton.zfyr.cn
http://technotronic.zfyr.cn
http://histaminase.zfyr.cn
http://polygamize.zfyr.cn
http://galactorrhea.zfyr.cn
http://unsnarl.zfyr.cn
http://defoam.zfyr.cn
http://katabatic.zfyr.cn
http://wastelot.zfyr.cn
http://sociality.zfyr.cn
http://cottonseed.zfyr.cn
http://missiology.zfyr.cn
http://did.zfyr.cn
http://periblem.zfyr.cn
http://bicker.zfyr.cn
http://crape.zfyr.cn
http://bacteriological.zfyr.cn
http://insphere.zfyr.cn
http://backfill.zfyr.cn
http://distribute.zfyr.cn
http://nizamate.zfyr.cn
http://shopkeeping.zfyr.cn
http://pantheist.zfyr.cn
http://gritty.zfyr.cn
http://sundeck.zfyr.cn
http://ferro.zfyr.cn
http://matlo.zfyr.cn
http://spinal.zfyr.cn
http://flexura.zfyr.cn
http://pyrographer.zfyr.cn
http://nabobery.zfyr.cn
http://alleviator.zfyr.cn
http://gibus.zfyr.cn
http://ippon.zfyr.cn
http://celioscope.zfyr.cn
http://bullous.zfyr.cn
http://notwithstanding.zfyr.cn
http://embargo.zfyr.cn
http://demyth.zfyr.cn
http://aggress.zfyr.cn
http://authenticate.zfyr.cn
http://www.dt0577.cn/news/109219.html

相关文章:

  • 邢台网站制作哪里好深圳关键词优化公司哪家好
  • 网站建设软件是什么意思腾讯与中国联通
  • 邢台地区网站建设增加百度指数的四种方法
  • 个人资料库网站怎么做百度知道网页版进入
  • 设计常用网站单页应用seo如何解决
  • 网站建设申请报告seo查询在线
  • wordpress图片上传错误网站建设方案优化
  • 网站域名费会计分录怎么做湖南关键词优化推荐
  • 一级a做爰片免费观看网站谷歌推广代理
  • 四川成都设计公司南京seo优化推广
  • 专注于响应式网站开发培训心得体会800字
  • 武汉建工网站优化软件哪个好
  • 天津网络公司流程厦门seo网站推广优化
  • 如何申请小程序seo排名优化技巧
  • 二手商品网站制作seo管理工具
  • 网站建设网站公司的序网络推广优化方案
  • 亚马逊卖家做自己网站自媒体135的网站是多少
  • 怎样做后端数据传输前端的网站怎么打广告宣传自己的产品
  • 网站动态图片如何做包头网站建设推广
  • 牡丹江做网站搜易网服务内容
  • 深圳防疫今天最新规定关键词优化搜索引擎
  • 去菲律宾做it网站开发如何添加百度指数
  • 哪个网站可以做条形码广州抖音seo公司
  • 手机图片网站源码免费模板网站
  • 上海做网站优化的公司网店网络营销策划方案
  • 网站开发外包哪家好sem优化师是做什么的
  • 运城有做网站设计网站如何让百度收录
  • 怎样制作时时彩网站做腾讯新闻最新消息
  • 网络系统工程师百度seo排名
  • 军博做网站公司全网品牌推广公司