- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 C++ 编程的新手。这些年来我做过一些 C#,但我不会说我精通它。我正在尝试将一些代码从 native c++ 更改为 C++/CX,并不断遇到很多编译器错误,特别是与 vector 有关的错误。我一直在阅读 MSDN - Collections (C++/CX)并收集到我需要使用 IVector。
我在另一个头文件中定义了一个结构:
typedef struct myStruct{
float p;
double x;
double y;
uint id;
}
我在方法声明中使用了这个结构的 vector 作为参数:
void ProcessStruct (std::vector<myStruct> myStructs){}
将其转换为 IVector 时,如下所示:
void ProcessStruct (Windows::Foundation::Collections::IVector<myStruct>^ myStructs){}
我总是遇到编译器错误 C3225 :“‘arg’的通用类型参数不能是‘type’,它必须是值类型或句柄类型”。我尝试使用 IVector<myStruct^>^
相反,但后来我以 C3699 结尾:“运算符”:不能在类型“类型”上使用此间接寻址”
所以我猜我唯一的选择是创建一个通用的,但在这里我对我实际应该做什么感到非常困惑。我如何获取结构并将其转换为泛型?什么是 std::vector 做而 IVector 做不到的?
最佳答案
首先,您需要使用 Platform::Collections::Vector 而不是 std::vector。它们基本上工作相同,因为它们的行为都像 vector ,但 Platform::Collections::Vector 是一个 WRT 对象,这就是我们使用 ^(帽子指针)来处理它们的原因。
我这样使用它:
public ref class Something{
public:
property Windows::Foundation::Collections::IVector<int>^ num{
void set(Windows::Foundation::Collections::IVector<int>^ e){
NUM = static_cast<Platform::Collections::Vector>(e);
};
Windows::Foundation::Collections::IVector<int>^ get(){
return NUM;
};
};
private:
Platform::Collections::Vector<int>^ NUM;
};
在某种意义上,您将 IVector 用作属性(因为属性可以是公共(public)成员),然后将其转换为 c++/cx Vector。稍后当您需要它时,使用 IVector 作为返回 Vector 的媒介。
另请注意,set 函数的参数是一个 IVector,get 函数也是一个 IVector 类型。
一些代码来帮助:)
void Something::SomeFunction(){
num = ref new Vector<int>; //make num point to a new Vector<int>
num->Append(5); //Take the number 5 cast it from IVector to Vector
//and store it in NUM. (The cast happens due to
//the code in the IVector property we made)
int TempNum = 7 + num->GetAt(0); //Use num to get the first element of NUM and
//add 7 to it. (It's now 10, I mean 12)
num->InsertAt(0, T); //Take T (12) and replace it with the first
//element in NUM.
};
请记住,当我们对 num 做某事时,它会被强制转换,而不是对 NUM 做。这就是为什么有一个接口(interface),它们帮助我们在 Java、C# 等之间使用 Vectors(或任何其他东西,如 String 或 Map)。
关于C++ 原生于 C++/CX:如何将 std::vector 转换为 IVector?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15974981/
NASM给出的错误(尽管我的操作系统正常)是“无效的有效地址”。 现在,我已经看到了许多关于如何使用LEA的示例,我认为我做对了,但是我的NASM不喜欢它。我尝试了lea cx, [cx+9]并成功了
我希望尽可能生成动态文本而不需要创建 webhook。我知道创建动态文本的唯一方法是根据参数创建不同的路由或通过 using inline system functions像文本实现中的 $sys.f
我需要知道如何查看实际对话以及与每个对话回合匹配的意图。 我在 上找不到完成对话/意图审查的方法Dialogflow CX 版。 (在 ES 版上非常简单)。 我需要访问他的功能(如果它在 CX 上实
我正在尝试填充 API 参数:https://cloud.google.com/dialogflow/cx/docs/quick/api . 我找不到任何关于如何在其文档中找到代理 ID 的引用:ht
我正在尝试填充 API 参数:https://cloud.google.com/dialogflow/cx/docs/quick/api . 我找不到任何关于如何在其文档中找到代理 ID 的引用:ht
我正在探索 Cx,这是一个基于 React ( http://cx.codaxy.com/ ) 的有趣的新框架,但我不知道如何访问组件内的 DOM 元素. 基本上,我有一个包含一些文本和一个按钮的简单
我是 WinRT 的新手。我正在将用 C++/CX 编写的 Windows UWP 应用程序转换为 C++/WinRT。我有一个 C++/CX ref 类,它基本上与 C# 中的 Microsoft.
每当我尝试在 DOSBox 下使用 MASM 6.15 时: mov al, [cx] 或者 mov al, [cx + bx] 或者 mov al, [cx + 4] 我收到错误消息:“只允许使用基
我想在 CDialog 的 OnInitDialog 期间获取 cx 和 cy。 我可以用下面的代码做到这一点: myDialog::OnInitDialog() { CRect rcWindow
这听起来像是一个愚蠢的问题,因为我知道这两种语言的实现是完全不同的。但是,我对细节有些不清楚。 我喜欢的 C++CLI 中一个非常好的特性是我可以拥有一个标准的 C# .NET 动态库并在 C++CL
我正在尝试使用 RPC DetectIntent 方法与 Dialogflow CX 代理交互,但出现错误“请切换到‘us-east1-dialogflow.googleapis.com’以访问位于‘
我有一个类: ref class Coord { public: property float X { float get() { return X; } vo
我是 C++/CX、IDL 和 WRL 的新手,遇到了一个问题我不确定是我的代码有错误还是设计的限制。 我有一个 IDL,它定义了一个 IInspectable 接口(interface)及其运行时类
我正在通过构建 Windows 应用商店应用来学习 C++/CX。对于我的 View 模型的基础,我使用标准的 BindableBase 类并向其添加了一个方便的 SetProperty 方法(我在我
我最近加入了一家新公司,并且是 python(他们首选的脚本语言)的新手,并且一直在使用 cx_oracle 创建一些 ETL 流程。到目前为止,我构建的脚本都是单线程作业,它们从 Oracle 源数
java.util.regex.Pattern 的 Javadoc 说 \cx 表示 x 对应的控制字符。所以我认为 Pattern.compile() 会拒绝 \c 后跟除 [@-_] 之外的任何字
我想使用 C++/CX 语法编写一个库并在其他项目中使用它。 如您所知,普通的旧数据结构不能有任何方法或运算符,因此我们不得不做一些事情,例如在另一个类中编写静态方法来提供行为。 我们也不能这样写代码
我正在尝试使用以下汇编代码将磁盘扇区加载到内存中,但正如我在终端中使用一些 int 0x10 时发现的那样,它不起作用的原因是它陷入了无限循环。我以为循环会自动为我递减 cx 寄存器。下面是代码,其中
我关注了this tutorial用于在 Mac 上安装 cx_oracle。经过一些调整,它成功了。我之前使用的是 Mavericks。然后我升级到 El Capitan。这就是灾难的来源。 它停止
我一直在学习x86汇编语言,PUSHA指令产生了一个问题。 据我所知,Pusha和PUSH AX, CX, DX, BX, original SP, BP, SI, DI一样。 我想知道的是为什么在
我是一名优秀的程序员,十分优秀!