不能将 "Struct*" 类型的值分配给类型 "Struct*" 的实体
a value of type "Struct*" cannot be assigned to an entity of type "Struct*"
>我有一个返回结构类型指针的函数。我想要的是pFacialFeatures指向与返回的指针相同的地址。
struct Features
{
CvRect* face_;
CvRect* nose_;
CvRect* eyesPair_;
CvRect* rightEye_;
CvRect* leftEye_;
CvRect* mouth_;
};
Features* Detect()
{
Features* facialFeatures = (Features*) malloc(sizeof(Features));
return facialFeatures;
}
int main(int argc, char* argv[])
{
Features* pFacialFeatures;
pFacialFeatures = Detect();
}
它给了我错误:
智能感知:无法将"功能 *"类型的值分配给类型为"功能 *"的实体
注意:也许您可能认为这个问题与这个问题相同。在这个问题中,声明结构存在问题。我真实地宣布了结构。
您以某种方式通知Visual Studio这是一个C源文件而不是C++源文件 - 也许通过将文件命名为"something.c"或将其放在头文件中,然后从".h"文件包含它,或者通过悬挂"extern C"或以某种方式将文件或项目的属性设置为"编译为C"。如果你使用的是Linux/MacOS,你可能已经通过使用C编译器而不是C++编译器来完成,例如,通过键入"gcc foo.cpp"而不是"g++ foo.cpp。
结构声明的 C 语言语法与 C++ 中的语法不同。
C++声明
struct Foo {}; // C++
在 C 中等效于此:
typename struct tagFoo {} Foo; // C
因此,以下代码可以在C++中工作,但在 C 中失败:
struct Foo {};
Foo* f = (Foo*)malloc(sizeof(Foo));
更改此内容以检查C++的快速方法是替换:
Features* facialFeatures = (Features*) malloc(sizeof(Features));
跟
Features* facialFeatures = new Features;
如果在 C 模式下编译,则会收到有关 new
的编译器错误。它是C++中的关键字,但在 C 中不是。
用 C 写行的方式是
struct Features* facialFeatures = malloc(sizeof* facialFeatures);
我相信
你需要在类型的声明之前放置结构:
struct Features* facialFeatures = (struct Features *)malloc(sizeof(struct Features));
相关文章:
- Openssl 1.1.1d无效使用不完整的类型"struct dsa_st"
- 数据类型"struct seq<0, 1, 2>{}"含义是什么?
- 返回类型为struct的函数每次调用时都不返回任何内容
- "typedef"类型名称是否可以像"struct"定义那样声明指向结构的指针?
- 错误 C2011 'vars::strct': 'struct' 类型重定义
- C++ 在"struct std::iterator_traits"中没有名为"value_type"的类型<int>
- 错误:未使用不完整的类型'struct std::hash<>'无效
- boost :: Spirit属性分配:struct is_nullary:基本类型无法成为结构或类型
- 引用绑定到类型 'struct value_type' 的 null 指针
- 如何使一种类型的STL对只占用另一种类型的空间"empty struct"?
- 错误 13 错误 C2011:'ConnectionInfo':'struct'类型重定义
- 读取struct类型的循环中的变量
- 如何从采用 int 和 struct 类型的指针的函数中取消引用指针返回的地址?
- 构建失败:重新定义;不同的基本类型和类型名称首次使用"类"出现,现在使用"struct"
- 如何在类中使用变量类型 Struct
- C++传递"struct"类型的参数作为引用 (&) 或按值传递
- 为什么boost::fusion序列中的struct数组成员类型不能正确推导
- struct作为c++中函数的类型
- 使用unordered_map以std::pair作为枚举类的键使用不完整类型struct std::hash无效
- 不能将 "Struct*" 类型的值分配给类型 "Struct*" 的实体