请先看代码:
class BM_FONT_CALL BMfont
{
public:
BMfont();
~BMfont();
bool Load(const std::string& fontName);
void Print(float x, float y);
class BM_FONT_CALL BMstring : public std::string
{
public:
BMstring() { }
BMstring(const char* str);
BMstring& operator=(const char* str);
BMstring operator+=(const char* str);
private:
void Compile();
};
public:
BMstring text;
float scale;
_uint32 tabSize;
_uint32 textureSheet;
_uint32 backTexture;
_uint32 frontTexture;
bool enableMasking;
_uint32 base;
_uint32 lineHeight;
_uint32 pages;
_uint32 scaleW, scaleH;
_uint32 kerninfo_count;
BMkerninfo *kerninfo;
BMchar chars[MAX_CHAR];
private:
std::string _fontName;
};
我如何才能BMstring
访问BMfont
的成员,就好像BMstring
不会继承BMfont
的成员一样?例如,如果我这样做:
BMfont::BMstring text;
text.scale //I don't want this
我在这里要做的是,我希望在没有任何inside实例的情况下BMstring::Compile()
可以访问。BMfont
BMfont
BMstring
或者如果我这样做:
class BM_FONT_CALL BMstring : public std::string
{
std::function<void (void)> func;
public:
BMstring() { func = BMfont::Compile(); }
}
通过使Compile()
. BMfont
但这不会编译。我怎样才能做到这一点?