c++ - OOP 冒泡排序 C++ 程序
问题描述
我收到这些错误编译器错误 C3867(((('func':函数调用缺少参数列表;使用'&func'创建指向成员的指针))))
没有什么
#include <iostream>
using namespace std;
class Cuzmo
{
private:
int array[1000];
int n;
public:
Cuzmo ()
{
int array[] = { 95, 45, 48, 98, 485, 65, 54, 478, 1, 2325 };
int n = sizeof (array) / sizeof (array[0]);
}
void printArray (int* array, int n)
{
for (int i = 0; i < n; ++i)
cout << array[i] << endl;
}
void bubbleSort (int* array, int n)
{
bool swapped = true;
int j = 0;
int temp;
while (swapped)
{
swapped = false;
j++;
for (int i = 0; i < n - j; ++i)
{
if (array[i] > array[i + 1])
{
temp = array[i];
array[i] = array[i + 1];
array[i + 1] = temp;
swapped = true;
}
}
}
}
};
int main ()
{
Cuzmo sort;
cout << "Before Bubble Sort :" << Cuzmo::printArray << endl;
cout << Cuzmo::bubbleSort << endl;
cout << "After Bubble Sort :" << Cuzmo::printArray << endl;
return (0);
}
我收到这些错误编译器错误 C3867(((('func':函数调用缺少参数列表;使用'&func'创建指向成员的指针))))
解决方案
这不是你调用f
没有参数的函数的方式:
f;
这就是你的做法:
f();
此外,您正在尝试发送 to 的返回值bubbleSort()
,cout
但没有这样的值,因为该函数具有void
返回类型。
实际上,您的printArray()
函数也是如此:它已经进行了打印,并且没有要发送到的结果值cout
。
尝试:
cout << "Before Bubble Sort :";
Cuzmo::printArray();
cout << endl;
Cuzmo::bubbleSort();
cout << "After Bubble Sort :";
Cuzmo::printArray();
cout << endl;
另一个问题是您array
在构造函数中声明和初始化了一个局部变量;此变量与成员无关。
您的变量也是如此n
。您不断地重新声明新的局部变量,这些变量会影响成员变量。
推荐阅读
- nlp - 尝试训练 spacy ner 管道以添加新命名实体时出现意外类型的 NER 数据
- c# - 与 C# 控制台应用程序中的相同代码相比,Regex.Match 在 Unity 中返回不同/错误的结果
- c++ - 无法解释为什么 c++ 向量分配失败
- android - 如何修复 Android Studio 模拟器总是向上旋转?
- python - 谷歌自己的参考示例甚至不起作用?为 GCS 编写自定义签名 URL
- rabbitmq - 基于 AMQP 的微服务注册和发现
- html - Gsap 滚动触发器混淆
- ios - Swift - 通过 UIRotationGestureRecognizer 旋转多个视图
- nextflow - Nextflow:使用 Google Life Sciences API 时指定启动映像
- linux - 如何使用 GNUplot 编辑 .plt 文件