zoukankan      html  css  js  c++  java
  • cc4ac++类定义与struct定义方式代码示范

    cc4a-c++类定义与struct定义方式代码示范

     1 #include <iostream>
     2 #include <string>
     3 using namespace std;
     4 
     5 struct People_C //struct定义方式,没有指定public,默认就是public
     6 {
     7 //public:
     8     //People_C( string &nm, string &addr):name(nm),address(addr)//此句没有const,所以报错。
     9         People_C( const string &nm, const string &addr):name(nm),address(addr)
    10 
    11         //严重性    代码    说明    项目    文件    行    禁止显示状态
    12         //错误    C2664    “People_C::People_C(People_C &&)” : 无法将参数 1 从“const char[3]”转换为“std::string &”    cc4a_demo    d : \users\tt2018\documents\visual studio 2015\projects\cc4a_demo\cc4a_demo\cc4a_demo.cpp    20
    13 
    14     {   }
    15     string getName()const { return name; }
    16     string getAddr()const { return address; }
    17 
    18 
    19 private:
    20     string name;
    21     string address;
    22 };
    23 class People 
    24 {
    25 public: //class定义方式,没有指定public,默认就是private
    26     People(const string &nm, const string &addr) :name(nm), address(addr)        
    27     {   }
    28     string getName()const { return name; }
    29     string getAddr()const { return address; }
    30 
    31 
    32 private:
    33     string name;
    34     string address;
    35 };
    36 int main()
    37 {
    38     struct People_C pp("bill","花果山");//struct写法
    39     class People pp1("bill-1", "花果山-1");//class写法,class可以不写
    40     cout << pp.getName() << "---" << pp.getAddr() << endl;
    41     cout << pp1.getName() << "---" << pp1.getAddr() << endl;
    42     getchar();
    43     return 0;
    44 }

    cc4a-c++类定义与struct定义方式代码示范

    欢迎讨论,相互学习。 txwtech@163.com
  • 相关阅读:
    JavaScript 以POST方式打开新页面
    C# 实现守护进程
    SQL Server 之 使用RowCount遍历表数据
    SQL Server 之 存储过程调用C#编写的dll文件
    C# 多线程学习整理
    java 学习的有用链接
    git 操作命令
    关于各种Map的那些事
    JAVA 反射机制详解
    深入理解java:注解(Anotation)自定义注解
  • 原文地址:https://www.cnblogs.com/txwtech/p/11867404.html
Copyright © 2011-2022 走看看