I want to re-define [] operator for a vector. I thought the simplest way to achieve this is to create my own class, say something like this (this is a simplified example):
class MyVec { private: std::vector<double> x; // I don't need a copy in here, it could be a reference public: MyVec(const std::vector<double>& y) { x = y; } double operator[](int i) { return x[i-1]; } }; Now the problem is that I basically do not need to copy data to x, I could store a reference to it, but as far as I know, I cannot use uninitialized references in class. Nonetheless, maybe there is some kind of workaround for this to work without copying the data?
std::stack, are expressively designed to be inherited from (std::stackhas aprotecteddata member). So clearly the ungoodness of the idea does not cover all cases. In my opinion it covers only a few special cases, that are usually not of any practical importance.