English 中文(简体)
rr编者不能将第2项从MyStruct1转换为无效*
原标题:Error compiler, cannot convert parameter 2 from MyStruct1 to const void*, for memcpy
  • 时间:2010-12-14 11:15:14
  •  标签:
  • c++
  • c
  • memcpy

我正试图将结构数据复制到另一个。 每种构件都能够处理。 我的声明和备忘录如下:

    typedef struct{
        CString strNumber;
        CString strAlpha;

    } _Number;

    typedef struct{
        CString strIterration;
        _Number NumberOne;
        _Number NumberTwo;
    } _Store;

_Store Data1;
_Store Data2;

现在,我要说,第一套结构数据1 已有数据,而第二个数据只是宣布的。

我使用以下法典:

memcpy(&Data2, Data1,   sizeof(_Store));

我无法按错误汇编。 任何想法? 复制数据的任何其他方法?

最佳回答

您需要使用<代码>&,涉及两个组成部分:

memcpy(&Data2, &Data1, sizeof(_Store));

Beware: _Store containedtring<>/code> member changing which (if it is such as MFC CString) is not bitwiseplicaable. 您仅应使用memcpy(>>,说明可复制的两种类型,否则,你有可能陷入不明确的行为。

问题回答

显而易见的其他做法是简单的转让,即数据2=数据1;

这使你无法照顾到有多少家 by在——商店结构中,也无法照顾到CString是否有一个经营者。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?