开发者

Using streams to initialise c++ objects

开发者 https://www.devze.com 2023-03-16 04:24 出处:网络
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 a

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 th开发者_运维问答at I can use?

What would the syntax look at the other end, when creating the object.

Thanks.


'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.


This other init is for constructing object from some stream: disc file, network data etc. In the case of AnimationPath you could have path defined in some file and use this method to load the data.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号