作者使用下面的伪代码是什么意思? 以下是B.Stroustrup的《C++程序设计语言》第三版第330页: template<class C> struct String<C>::Srep { C* s; // pointer to elements int sz; // number of elements int n; // reference count // ... }; template<class C> C String<C>::read(int i) const { return rep->s[i];} template<class C> String<C>::String() { p = new Srep(0, C()); } 模板结构字符串::Srep{ C*s;//指向元素的指针 int sz;//元素数 int n;//引用计数 // ... }; 模板C字符串::read(inti)const{return rep->s[i];} 模板字符串::字符串() { p=新的Srep(0,C()); }

作者使用下面的伪代码是什么意思? 以下是B.Stroustrup的《C++程序设计语言》第三版第330页: template<class C> struct String<C>::Srep { C* s; // pointer to elements int sz; // number of elements int n; // reference count // ... }; template<class C> C String<C>::read(int i) const { return rep->s[i];} template<class C> String<C>::String() { p = new Srep(0, C()); } 模板结构字符串::Srep{ C*s;//指向元素的指针 int sz;//元素数 int n;//引用计数 // ... }; 模板C字符串::read(inti)const{return rep->s[i];} 模板字符串::字符串() { p=新的Srep(0,C()); },c++,templates,C++,Templates,我对上述构造函数有两个问题: 1) p不应该被rep代替吗 2) ctorSrep(0,C())如何在存储中构造Srep对象?到1):是。在我的书中,我有以下代码: template<class C> struct String<C>::Srep { C* s; // pointer to elements int sz; // number of elements int n; // reference count }; template<cla

我对上述构造函数有两个问题:

1)
p
不应该被
rep
代替吗

2) ctor
Srep(0,C())
如何在存储中构造
Srep
对象?

到1):是。在我的书中,我有以下代码:

template<class C> struct String<C>::Srep {
  C* s;   // pointer to elements
  int sz; // number of elements
  int n; // reference count
};

template<class C> C String<C>::read(int i) cont { return rep->s[i];}

template<class C> String<C>::String<C>()
{
  rep = new Srep(0, C());
}
模板结构字符串::Srep{
C*s;//指向元素的指针
int sz;//元素数
int n;//引用计数
};
模板C字符串::read(inti)cont{return rep->s[i];}
模板字符串::字符串()
{
rep=新的Srep(0,C());
}

已经有20多次打印,在我的版本中,p是rep.@Red Serpent,但是构造函数调用如何
Srep(0,C())
?这不是“伪代码”,它是真实代码中的一个通用实现。曾经有过,可能会有一些输入错误。参阅“C++编程语言(第二版)”1991,(这是同一版本,但德语)。这段代码你也可以通过谷歌找到,看看:@duDE对我的第二个问题有什么评论吗?我的意思是,这只是一段伪代码,意味着,在字符串的ctor中,将被crteated一个结构Srep的新实例,而没有其他(…)?