I'm not sure to understand how the "serialization" works in your exemple.
What is ar ?
ar >> m_pFont
m_pFont is a pointer, so in my opinion, there is no allocation here, only a pointer (ar) affected to another pointer (m_pFont). You probably have one instance of your font ( managed by your code or the library, I don't know ) referenced ( pointed ) by several m_pFont.
You appear to be confusing serialization and deserialization. The first line above ar >> m_pFont; is deserializing from the archive into the m_pFont object. So where is the deserialize code that loads the object from the archive, and what type is m_pFont?
Well your code remains unclear. However, if m_pFont is a pointer, then you are going to have problems unless you also serialize the object that it is pointing at. Deserializing a pointer without the underlying object means that it will be pointing to some random portion of memory.
This point is treated by the MFC CArchive::ReadObject and CArchive::WriteObject methods which are automatically called by the >> or << operator. They are able to detecte or serialize the associated RuntimeClass.
The example code is very close to the actual code and the problem is that sometimes, depending on the computer, because of the operator >> to deserialize the style m_pFont, several m_pFont pointed to the same memory area.
I studied the problem with a minimal grid ... and finally realized that in my application I was not using this m_pFont. I modified my code so that I would no longer use it at all, destroy it and set it to NULL which definitively resolved my problem.
If I don't fully explain the phenomenon, I think it comes from the fact that these m_pFont contained the same data and that the operators << consider the pointer had already been serialized as explained in the TN002: Persistent Object Data Format | Microsoft Docs ... Maybe ...
Other application can print out without problem ? Have tried to print to another printer ? Or, have you tried to run that command on another machine ? You can find more if you do some debugging on your code ...
<l>I am trying to learn c++ programming language and am still an amateur at it. I have a problem with "passing arrays in a function" and all am asking is what would be the easiest way to handle this problem?