首页 > 应用开发 > > c++类的属性是存在数组里吗
#include "stdafx.h"
#include<iostream>
#include<cstring>
using namespace std;
class Clazz
{
public:
float x, y;
string msg;
const float& operator [] (uint8_t i) const { return (&x)[i]; }
float& operator [] (uint8_t i) { return (&x)[i]; }
Clazz() {}
Clazz(float x, float y, string msg) :x(x), y(y), msg(msg) {}
};
int main(void)
{
Clazz clazz = Clazz(1.0f,2.0f,"hello world");
cout << "clazz.x: " << clazz.x << endl;
cout << "clazz.y: " << clazz.y << endl;
cout << "clazz[0] " << clazz[0] << endl;
cout << "clazz[1] " << clazz[1] << endl;
cout << "clazz[2] " << clazz[2] << endl;
cin.get();
return 0;
怎么理解,有权威的解读或者定义能够解释吗
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2231/viewspace-3138615/ ,如需转载,请注明出处,否则将追究法律责任。