C ++中的混合管理 [英] Mixed management in C++

查看:530
本文介绍了C ++中的混合管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我向我的程序添加了一个类并测试了它。我真的很惊讶,有任何真正的错误。这里是代码:

I have added a class to my program and tested it. I was really surprised that there was any real errors. Here is the code:

#pragma once
#include "Iingredient.h"
#include <string>
#include <vector>

using namespace std;

ref class Recipe{
private:
    string partsName;
    vector<Iingredient> ing;
public:
    Recipe(){}

};

这里有错误:


错误23错误C4368:不能将partsName定义为托管
的成员'Recipe':混合类型不支持
支持c:\users\user\documents \visual studio
2010\projects\smestras2_l1\Recipe.h 10 1 file2_L1

Error 23 error C4368: cannot define 'partsName' as a member of managed 'Recipe': mixed types are not supported c:\users\user\documents\visual studio 2010\projects\smestras2_l1\Recipe.h 10 1 file2_L1

错误24错误C4368:无法将ing定义为管理的成员
'配方':混合类型不是
支持c:\users\user\documents\visual studio
2010 \projects\smestras2_l1\ Recipe。 h 11 1 file2_L1

Error 24 error C4368: cannot define 'ing' as a member of managed 'Recipe': mixed types are not supported c:\users\user\documents\visual studio 2010\projects\smestras2_l1\Recipe.h 11 1 file2_L1

我googled了一下,发现它关于托管和非托管代码。
如何解决这个问题?它与manged和非托管代码有关吗?如果是这样,

I googled a bit and found out that its about managed and unmanaged code. How to fix this? Is it related with manged and unmanaged code or not? if so how?

推荐答案

当定义 ref class Recipe 。但 std :: string std :: vector 是管理类型。您试图在托管类中声明本机变量,但不允许。

When defining ref class Recipe, you made it managed. But std::string and std::vector are umanaged types. You are trying to declare native variables in managed class, but it is not allowed.

看来,你是C ++的新手。只是,不要使用C ++ / CLI。考虑C#,如果你的目标.Net或非托管C ++。

Seems, you are novice in C++. Just, don't use C++/CLI. Consider C#, if you target .Net or unmanaged C++.

这篇关于C ++中的混合管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆