c_cpp C ++结构示例

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp C ++结构示例相关的知识,希望对你有一定的参考价值。

struct Company{
  public:
  //SETTERS
    bsl::string & tkr() { return d_tkr;}
    Share & shares() { return d_shares;}
    
    // GETTERS
    const bsl::string & tkr() const {return d_tkr;}
    // We return a reference instead of string because string is more expensive to struct.
    const Shares shares() const {return d_shares;}
    // The first const says the return type is const. This has no benefit when return a non-pointer variable,
    // becuase it will be made a copy anyways.
    // The second const is a method signature, says the logic state of the object can not change.
    // meaning a function that will not alter any member variables of the class it belongs to
    // On a const object only the const method are callable.
    // MISC
    
    //Better implementation:
    Shares shares() const {return d_shares;}
    //By not returning a reference, it is equivalent to 
    const Share & shares() const {return d_shares;}
  private:
    bsl::string d_tkr;
    Shares d_shares;
}

以上是关于c_cpp C ++结构示例的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp C ++结构

c_cpp C - 结构

c_cpp C ++数据结构

c_cpp 基本的c结构

c_cpp C程序的基本结构

c_cpp cpp c样式​​结构转换