首页 > 解决方案 > 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'创建指向成员的指针))))

标签: c++oop

解决方案


这不是你调用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。您不断地重新声明新的局部变量,这些变量会影响成员变量。


推荐阅读