繁体   English   中英

OOP 冒泡排序 C++ 程序

[英]OOP Bubble sort C++ program

我收到这些错误 Compiler Error C3867 (((( 'func': function call missing argument list; use '&func' to create a pointer to member ))))

没有什么

#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);
}

我收到这些错误 Compiler Error C3867 (((( 'func': function call missing argument list; use '&func' to create a pointer to member ))))

这不是您在没有 arguments 的情况下调用 function f的方式:

f;

这就是你的做法:

f();

此外,您正在尝试将bubbleSort()的返回值发送到cout ,但没有这样的值,因为 function 具有void返回类型。

实际上,您的 printArray printArray() function 也是如此:它已经进行了打印,并且没有结果值要发送到cout

尝试:

cout << "Before Bubble Sort :";
Cuzmo::printArray();
cout << endl;

Cuzmo::bubbleSort();

cout << "After Bubble Sort :";
Cuzmo::printArray();
cout << endl;

另一个问题是您在构造函数中声明和初始化了一个局部变量array 此变量与成员无关。

您的变量n也是如此。 您不断地重新声明新的局部变量,这些变量会影响成员变量。

也许您只是在 function 调用后忘记了括号? 试试Cuzmo::printArray()Cuzmo::bubbleSort() 此外,您可能希望使用 std::vector 而不是固定大小的 int 数组(以便循环遍历实际条目而不是 10000 个大部分未初始化的值)并查看 std::swap。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM