使用流来初始化 c++物体
我正在阅读 Game Coding Complete ,它建议有两个 init() 函数,一个是通常的 init() 调用,另一个采用流。但它并没有详细介绍它,我有点困惑。
class AnimatinPath
{
public:
AnimationPath();
Initialize(std::vector<AnimationPathPoints> const & srcPath);
Initialize(InputStream & stream);
// ...
};
它接着说你可以从磁盘、内存或通过网络初始化对象。
什么是流?我使用 C++ 已有大约 2 年了,我对 stream
的唯一体验是 iostream。这是否表明我有一个可以使用的对象的二进制输出?
创建对象时,另一端的语法会是什么样子。
谢谢。
I am reading Game Coding Complete
and it suggests to have two init()
functions, one being your usual init() call, the other taking a stream. It doesn't go into alot of detail about it though, and I am left a little confused.
class AnimatinPath
{
public:
AnimationPath();
Initialize(std::vector<AnimationPathPoints> const & srcPath);
Initialize(InputStream & stream);
// ...
};
It goes on to say you can init objects from disk, memory or over a network.
What is a stream? I've been using C++ for about 2 years and my only experience with stream
is iostream. Is this suggesting I have a binary output of an object that I can use?
What would the syntax look at the other end, when creating the object.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“流”其实并不重要。
第二个带有流参数的 init 函数意味着对象序列化。
看看这篇文章: How do you serialize an object in C++ ?
您可以在 google 上搜索“对象序列化”以获取更多信息。
'Stream' is actually not important.
Second
init
function with a stream parameter means object serialization.Take a look at this SO post: How do you serialize an object in C++?
You could google for 'object serialization' for more information.
这个另一个
init
用于从某些流构造对象:光盘文件、网络数据等。在AnimationPath
的情况下,您可以在某些文件中定义路径并使用此方法加载数据。This other
init
is for constructing object from some stream: disc file, network data etc. In the case ofAnimationPath
you could have path defined in some file and use this method to load the data.