沒看過這樣用template
// Texture.hclass Texture { public: friend class IResourceLoader; uint width() const { return mWidth; } uint height() const { return mHeight; } // We declare a templated inner class here (but not defined yet) template<class> class PrivateAccessor; //看不懂@@ private: uint mWidth; uint mHeight; };class IResourceLoader {}; // JpegLoader.cpp// Define Texture::PrivateAccessor here, access what ever you wanttemplate<> //看不懂@@class Texture::PrivateAccessor<jpegloader> {public: static size_t& width(Texture& texture) { return texture.mWidth; } static size_t& height(Texture& texture) { return texture.mHeight; }};typedef Texture::PrivateAccessor<jpegloader> Accessor;void JpegLoader::load() { // ... Accessor::width(mTexture) = 128; // Ok! no problem Accessor::height(mTexture) = 128;}
沒有留言:
張貼留言