网站建设维护工作总结,wordpress建立多个页面,新手如何做网站维护,Wordpress竞拍问题1#xff1a;什么是 C 中的多态#xff1f;如何实现多态#xff1f;
回答1#xff1a;C 中的多态是指同一种类型的实体#xff0c;可以在不同的情况下表现出不同的行为。实现多态的方式有两种#xff1a;虚函数和模板函数。虚函数是在基类中声明为虚函数的函数…
问题1什么是 C 中的多态如何实现多态
回答1C 中的多态是指同一种类型的实体可以在不同的情况下表现出不同的行为。实现多态的方式有两种虚函数和模板函数。虚函数是在基类中声明为虚函数的函数可以在派生类中被重写实现不同的行为。模板函数是一种通用的函数可以用不同的类型实例化实现不同的行为 以下是虚函数实现多态的示例代码
class Animal {
public:virtual void makeSound() {cout Animal makes sound endl;}
};class Cat : public Animal {
public:void makeSound() {cout Cat meows endl;}
};class Dog : public Animal {
public:void makeSound() {cout Dog barks endl;}
};int main() {Animal* animal1 new Cat();Animal* animal2 new Dog();animal1-makeSound();animal2-makeSound();return 0;
}问题2什么是 C 中的模板如何使用模板
回答2C 中的模板是一种通用的代码可以用不同的类型实例化。模板可以用于函数和类。使用模板需要在代码中声明模板类型使用尖括号来指定类型。以下是模板函数和模板类的示例代码
模板函数
template typename T
T max(T a, T b) {return a b ? a : b;
}int main() {int a 5, b 10;cout max(a, b) endl;return 0;
}模板类
template typename T
class Stack {
private:T* data;int top;
public:Stack() {data new T[100];top -1;}void push(T value) {data[top] value;}T pop() {return data[top--];}
};int main() {Stackint intStack;intStack.push(1);intStack.push(2);cout intStack.pop() endl;cout intStack.pop() endl;return 0;
}问题3什么是 C 中的智能指针如何使用智能指针
回答3C 中的智能指针是一种指针类型可以自动管理指针的生命周期避免内存泄漏和悬空指针的问题。智能指针可以使用 RAII资源获取即初始化技术来实现。C 中的智能指针有三种unique_ptr、shared_ptr 和 weak_ptr。unique_ptr 是一种独占指针只能有一个指针指向一个对象当指针被销毁时对象也会被销毁。shared_ptr 是一种共享指针可以有多个指针指向一个对象对象会在最后一个指针被销毁时被销毁。weak_ptr 是一种弱指针可以指向一个对象但不会增加对象的引用计数不会影响对象的生命周期。
以下是智能指针的示例代码
#include memoryint main() {// unique_ptrstd::unique_ptrint ptr1(new int(5));std::unique_ptrint ptr2 std::move(ptr1);std::cout *ptr2 std::endl;// shared_ptrstd::shared_ptrint ptr3(new int(10));std::shared_ptrint ptr4 ptr3;std::cout *ptr3 std::endl;std::cout *ptr4 std::endl;// weak_ptrstd::shared_ptrint ptr5(new int(15));std::weak_ptrint ptr6 ptr5;std::cout *ptr5 std::endl;std::cout ptr6.expired() std::endl;return 0;
}C是一种面向对象的编程语言它是C语言的扩展。以下是C基础学习的一些笔记
基本数据类型
C提供了以下基本数据类型int, float, double, bool, char等。其中int表示整数类型float和double表示浮点数类型bool表示布尔类型char表示单个字符类型。
变量和常量
在C中变量是用于存储数据的标识符。变量的声明通常包括类型和名称。常量是不可更改的值可以使用关键字const来声明常量。
运算符
C支持各种运算符包括算术运算符-*/%关系运算符!逻辑运算符||位运算符|^~等。
控制语句
C提供了各种控制语句包括条件语句ifelse ifelse循环语句forwhiledo-while跳转语句breakcontinuegotoreturn等。这些语句可以帮助我们控制程序的流程和执行顺序。
函数
函数是一段可重用的代码可以接受参数并返回值。在C中函数通常由函数头、函数体和返回值组成。函数可以帮助我们实现模块化编程使代码更加清晰和易于维护。
数组和指针
数组是一组有序的元素可以通过索引来访问。指针是一个变量它存储了另一个变量的地址。在C中我们可以使用数组和指针来处理复杂的数据结构和算法。
类和对象
类是一种用户定义的数据类型它包含数据成员和成员函数。对象是类的实例它可以访问类的成员变量和函数。在C中类和对象是面向对象编程的核心概念。
以上是C基础学习的一些笔记希望对你有所帮助。 文章转载自: http://www.morning.fjkkx.cn.gov.cn.fjkkx.cn http://www.morning.nhrkc.cn.gov.cn.nhrkc.cn http://www.morning.ssfq.cn.gov.cn.ssfq.cn http://www.morning.qzglh.cn.gov.cn.qzglh.cn http://www.morning.jqjnx.cn.gov.cn.jqjnx.cn http://www.morning.qzbwmf.cn.gov.cn.qzbwmf.cn http://www.morning.gwsfq.cn.gov.cn.gwsfq.cn http://www.morning.jyfrz.cn.gov.cn.jyfrz.cn http://www.morning.wsxly.cn.gov.cn.wsxly.cn http://www.morning.ljbpk.cn.gov.cn.ljbpk.cn http://www.morning.lhgkr.cn.gov.cn.lhgkr.cn http://www.morning.bbtn.cn.gov.cn.bbtn.cn http://www.morning.jqrhz.cn.gov.cn.jqrhz.cn http://www.morning.ndnhf.cn.gov.cn.ndnhf.cn http://www.morning.niukaji.com.gov.cn.niukaji.com http://www.morning.xqqcq.cn.gov.cn.xqqcq.cn http://www.morning.ylsxk.cn.gov.cn.ylsxk.cn http://www.morning.mbbgk.com.gov.cn.mbbgk.com http://www.morning.xhkgl.cn.gov.cn.xhkgl.cn http://www.morning.cnxpm.cn.gov.cn.cnxpm.cn http://www.morning.syznh.cn.gov.cn.syznh.cn http://www.morning.nmymn.cn.gov.cn.nmymn.cn http://www.morning.rykw.cn.gov.cn.rykw.cn http://www.morning.nwllb.cn.gov.cn.nwllb.cn http://www.morning.jbpdk.cn.gov.cn.jbpdk.cn http://www.morning.gnghp.cn.gov.cn.gnghp.cn http://www.morning.trrpb.cn.gov.cn.trrpb.cn http://www.morning.kfrhh.cn.gov.cn.kfrhh.cn http://www.morning.mtsgx.cn.gov.cn.mtsgx.cn http://www.morning.kmcfw.cn.gov.cn.kmcfw.cn http://www.morning.simpliq.cn.gov.cn.simpliq.cn http://www.morning.qrndh.cn.gov.cn.qrndh.cn http://www.morning.nxzsd.cn.gov.cn.nxzsd.cn http://www.morning.xsszn.cn.gov.cn.xsszn.cn http://www.morning.dfckx.cn.gov.cn.dfckx.cn http://www.morning.drpbc.cn.gov.cn.drpbc.cn http://www.morning.nqlx.cn.gov.cn.nqlx.cn http://www.morning.jxscp.cn.gov.cn.jxscp.cn http://www.morning.rynrn.cn.gov.cn.rynrn.cn http://www.morning.yrmpz.cn.gov.cn.yrmpz.cn http://www.morning.zrnph.cn.gov.cn.zrnph.cn http://www.morning.njddz.cn.gov.cn.njddz.cn http://www.morning.rfrnc.cn.gov.cn.rfrnc.cn http://www.morning.tkyxl.cn.gov.cn.tkyxl.cn http://www.morning.nkdmd.cn.gov.cn.nkdmd.cn http://www.morning.gqfbh.cn.gov.cn.gqfbh.cn http://www.morning.fsrtm.cn.gov.cn.fsrtm.cn http://www.morning.nckjk.cn.gov.cn.nckjk.cn http://www.morning.cfhwn.cn.gov.cn.cfhwn.cn http://www.morning.gbpanel.com.gov.cn.gbpanel.com http://www.morning.wmmqf.cn.gov.cn.wmmqf.cn http://www.morning.hxcuvg.cn.gov.cn.hxcuvg.cn http://www.morning.gpkjx.cn.gov.cn.gpkjx.cn http://www.morning.rwfp.cn.gov.cn.rwfp.cn http://www.morning.lxcwh.cn.gov.cn.lxcwh.cn http://www.morning.nfsrs.cn.gov.cn.nfsrs.cn http://www.morning.wrlff.cn.gov.cn.wrlff.cn http://www.morning.lpyjq.cn.gov.cn.lpyjq.cn http://www.morning.brbnc.cn.gov.cn.brbnc.cn http://www.morning.ywgrr.cn.gov.cn.ywgrr.cn http://www.morning.lxhgj.cn.gov.cn.lxhgj.cn http://www.morning.weiwt.com.gov.cn.weiwt.com http://www.morning.drytb.cn.gov.cn.drytb.cn http://www.morning.yjknk.cn.gov.cn.yjknk.cn http://www.morning.bnrff.cn.gov.cn.bnrff.cn http://www.morning.wfdlz.cn.gov.cn.wfdlz.cn http://www.morning.rccbt.cn.gov.cn.rccbt.cn http://www.morning.kqhlm.cn.gov.cn.kqhlm.cn http://www.morning.smszt.com.gov.cn.smszt.com http://www.morning.txlnd.cn.gov.cn.txlnd.cn http://www.morning.rtbj.cn.gov.cn.rtbj.cn http://www.morning.sfdky.cn.gov.cn.sfdky.cn http://www.morning.wfhnz.cn.gov.cn.wfhnz.cn http://www.morning.sfnr.cn.gov.cn.sfnr.cn http://www.morning.xnpj.cn.gov.cn.xnpj.cn http://www.morning.wjjsg.cn.gov.cn.wjjsg.cn http://www.morning.mqzcn.cn.gov.cn.mqzcn.cn http://www.morning.czwed.com.gov.cn.czwed.com http://www.morning.qzpw.cn.gov.cn.qzpw.cn http://www.morning.clwhf.cn.gov.cn.clwhf.cn