在基于Windows应用程序表单的项目中工作时创建新类。我有一个问题,字符串变得无法使用。我发现了像
这样的错误"托管类的成员不能是非托管类类型"
" IntelliSense:涉及通用参数的函数类型不能有省略号参数"
"智能感知:链接规范与先前的" bsearch_s"(在第426行声明)"
不兼容Person.h
#pragma once
#include <string>
using namespace std;
ref class Person
{
public:
Person(void);
string name;
};
Person.cpp
#include "stdafx.h"
#include "Person.h"
#include <string>
using namespace std;
Person::Person(void)
{
name = "Bob";
}
如果某人有解决方案,或者解决了不能创建自己的字符串课程的问题,我很乐意听到它,因为这已经困扰了我好几天。
答案 0 :(得分:0)
CLI C ++中的字符串标头已包含在System命名空间中。 String作为指针。使用cap ^ handler
//This works:
#include "stdafx.h"
using namespace System;
void function()
{
String^ simpleStr = "Bob";
}