类型 myObj 和 myObj* 不兼容
Types myObj and myObj* are not compatible
class boundaryPt{
public:
friend class KCurvature;
int x;
int y;
boundaryPt(int x, int y){
this->x = x;
this->y = y;
}
boundaryPt(){}
};
class KCurvature{
public:
boundaryPt* boundaryPtAry;
int numPts;
ifstream input;
KCurvature(char* inFile){
input.open(inFile);
input >> numPts;
boundaryPtAry = new boundaryPt[numPts];
}
void loadData(char* inFile){
input.open(inFile);
int x;
int y;
while(!input.eof()){
input >> x;
input >> y;
boundaryPtAry[index++] = new boundaryPt(x,y);
}
};
我的问题是:
boundaryPtAry[index++] = new boundaryPt(x,y);
我正在尝试将我的 boundaryPt 对象存储在我的 boundaryPt 类型数组中,但由于我将该数组声明为 boundaryPt*,因此不允许我存储 boundaryPt。
这是一个引用指针的简单问题吗?我对C++生疏了。
解决了!我现在意识到,在创建对象数组时,您不仅要创建数组,还要创建对象本身。因此,无需创建一个新对象并尝试将其放入数组中(或者在我的情况下将数组索引指向它)。
while(!input.eof()){
input >> boundaryPtAry[index].x;
input >> boundaryPtAry[index].y;
index++;
}
相关文章:
- 我收到同义重复编译器错误。我应该如何修复"类型"X"的参数与类型"X"的参数不兼容?
- 字符类型转换不兼容
- Qt:如何使不兼容的发送方/接收方参数兼容?
- 视觉工作室 2017;启用 /permissive 时,类型 "const wchar_t *" 的参数与类型 "PWSTR" 的参数不兼容
- 使用不兼容的分配器复制分配无序列图
- 类型为 "int*" 的参数与 C++ 中错误类型"int**"参数不兼容
- 该对象具有与成员函数不兼容的类型限定符.为什么会出现此错误?
- 我正在尝试将表的地址传递给要在另一个函数中使用的指针,但得到不兼容的指针类型
- 为什么范围算法与 std 的迭代器不兼容?
- Winpcap Findalldevs const char * 与 char * 不兼容
- C++ 类型的参数与 void (__cdecl*)(void) 类型的参数不兼容,当调用 std::atexit()
- 将"std::string {aka std::basic_string}"赋值中的不兼容类型<char>
- 如何在C++中停止调用不兼容的方法?
- OPENCL 警告:不兼容的指针类型将'float __global[16]'传递给类型为 '__global float4 的参数 *
- 函数范围的静态变量如何导致与共享库中函数代码的未来使用不兼容
- 如何修复"方法的类型与 PInvoke 不兼容"
- C++不兼容的迭代器类型
- 编译器错误"在if语句中分配不兼容的类型"
- 程序无法编译:将 'int (*)[3][3]' 赋值为 'int [9][3][3]' 中的不兼容类型
- 类型 myObj 和 myObj* 不兼容