I have class with some nested classes and struct
template<typename Str>
class DeferredString {
private:
// Representation of a shared string
struct StringRep;
StringRep* _rep;
// Proxy class for a character in the string
class CharProxy;
public:
DeferredString();
DeferredString(const string&);
DeferredString(const DeferredString<Str>&);
DeferredString(const char*);
~DeferredString();
DeferredString<Str>& operator=( const DeferredString<Str>&);
DeferredString<Str>& operator=( const char* );
void check(size_t i) const;
char read(int i) const;
void write (int i, char c);
CharProxy operator[](int i);
char operator[](int i) const;
int length()const;
};
This is realization of nested class and struct:
template<typename Str>
class DeferredString<Str>::CharProxy
{
friend class DeferredString<Str>;
private:
// String to which belongs proxy
DeferredString<Str> & _proxyship;
// Character substituted by a proxy
int _index;
CharProxy(DeferredString<Str>& ds, int i);
public:
const char* operator&() const;
char* operator&();
operator char() const;
operator char&();
CharProxy& operator=(char c);
ostream& operator<<(ostream & os);
};
template<typename Str>
struct DeferredString<Str>::StringRep
{
// pointer to the allocation og a string
Str* _allocator;
// number of characters in the string
size_t _len;
// how many oblects use this representation
int _refCounter;
// if the string may be sharable
bool _shareable;
StringRep(size_t, const char*);
StringRep(size_t, const string&);
~StringRep();
// pseudo copy constructor
StringRep* getOwnCopy();
// pseudo assignment
void assign(size_t, const char*);
void makeShareable() { _shareable = true; }
void makeUnshareable() { _shareable = false; }
bool isShareable() const { return _shareable; }
private:
// Wil never be implemented
StringRep(const StringRep&);
StringRep& operator= (const StringRep&);
};
And after I run the program I have many errors in realization. For example:
template<typename Str>
DeferredString<Str>::CharProxy DeferredString<Str>::operator[](int i)
{
check(i);
// A proxy will be returned instead of a character
return CharProxy(*this, i);
}
compiler said that Error C2061 syntax error: the identifier "CharProxy" And so many. I don't know what the problem is here. Can you help me?