You can do the same thing by using a zero sized array (which anon also made mention of) though either way issues warnings or errors on all the compilers I use.
The idea is (and I use this a lot, so don't think its useless or stupid)...
Example:
Code:
struct my_bstr
{
private:
size_t length, capacity;
char data[]; // it has to be the last member for this to work.
public:
explicit my_bstr(const char *literal) : length(0), capacity(0)
{
for(register const char *i = literal; *i; ++i,++length)
;
capacity = length * 2; // this is a stupid algo, but I am just trying to demonstrate a point.
}
virtual ~my_bstr() { }
operator const char *() const
{
return data;
}
};
The string doesn't require a null terminator or anything like that since that is not how it is stored internally. This is more like how PASCAL's string objects are stored. Though, not exactly the same.