Спасибо, explicit помог
C++ |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
| class cTag
{ private:
class baseTag : public std::string
{ public:
baseTag(const std::string &s) : std::string(s) {}
baseTag(const char *s) : std::string(s) {}
};
public:
class FullTag : public baseTag
{ public:
explicit FullTag(const std::string &s) : baseTag(s) {}
explicit FullTag(const char *s) : baseTag(s) {}
};
static std::string Tag(const FullTag &T, const std::string &Param, const std::string &Body)
{ return "<"+T+Param+">"+Body+"</"+T+">";}
static const FullTag a;
//-----
class ShortTag : public baseTag
{ public:
explicit ShortTag(const std::string &s) : baseTag(s) {}
explicit ShortTag(const char *s) : baseTag(s) {}
};
static std::string Tag(const ShortTag &T, const std::string &Param)
{ return "<"+T+Param+" />"; }
static const ShortTag input;
};
const cTag:: FullTag cTag::a("a");
const cTag::ShortTag cTag::input("input");
int main(int argc, char *argv[], char *env[])
{ system("clear");
std::cout<<cTag::Tag(cTag::a ," b","c")<<std::endl;
std::cout<<cTag::Tag(cTag::input," b" )<<std::endl;
//std::cout<<cTag::Tag(cTag::a ," b" )<<std::endl;
//std::cout<<cTag::Tag(cTag::input," b","c")<<std::endl;
cTag:: FullTag vFullTag ("Full_Tag");
cTag::ShortTag vShortTag("Short_Tag");
//vFullTag=vShortTag;
cTag::FullTag vFullTag2(vShortTag);
return 0;
} |
|
Осталась только 42 строка, но мне кажется, от этого не избавиться без принципиальной переделки класса. Т.е. vShortTag при обращении через ссылку на std::string раскрывает все свои методы и данные, а попытка использования в наследовании вместо
public baseTag private/protected baseTag не позволит компилировать функции cTag::Tag.