gpt4 book ai didi

c++ - 作者用下面的伪代码是什么意思?

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:03:51 25 4
gpt4 key购买 nike

以下内容摘自 B.Stroustrup 的“The C++ Programming Language”第三版第 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());
}

关于上面的构造函数我有两个问题:

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());
}

关于c++ - 作者用下面的伪代码是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15055227/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com