Dzwebs.Net

撰写电脑技术杂文十余年

c++类class链式调用函数的例子

Admin | 2025-10-15 8:58:29 | 被阅次数 | 3

温馨提示!

如果未能解决您的问题,请点击搜索;登陆可复制文章,点击登陆

c++类class链式调用函数的例子

#include <iostream>

using namespace std;
class productinfor{
  private:
  string name;
  float age;
  public:
  productinfor setname(const string n){
  name = n;
  return *this;
}
  productinfor setage(const float v){
  age = v;
  return *this;
}
  void printnameage(){
  cout << "My name is " << name << ", and I am " << age << " years old." << endl;
}
};
int main(){
  productinfor p;
  p.setname("青山").setage(44.3).printnameage();
  p.setname("南山").setage(43.4).printnameage();

}

输出
My name is 青山, and I am 44.3 years old.
My name is 南山, and I am 43.4 years old.


该杂文来自: 最新技术

上一篇:vue3同一个HTML5页面,通过type="module"创建多个

下一篇:暂时没有文章了

网站备案号:

网站备案号:滇ICP备11001339号-7

版权属性:

Copyright 2007-2021-forever Inc. all Rights Reserved.

联系方式:

Email:dzwebs@126.com QQ:83539231 访问统计