Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
163 views
in Technique[技术] by (71.8m points)

OOP Bubble sort C++ program

I am getting these errors Compiler Error C3867 (((( 'func': function call missing argument list; use '&func' to create a pointer to member ))))

nothing

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

I am getting these errors Compiler Error C3867 (((( 'func': function call missing argument list; use '&func' to create a pointer to member ))))

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is not how you call a function f with no arguments:

f;

This is how you do it:

f();

Furthermore, you're trying to send the return value of bubbleSort() to cout, but there is no such value as the function has void return type.

In fact, the same is true of your printArray() function: it already does the printing, and there is no result value to send to cout.

Try:

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

Cuzmo::bubbleSort();

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

The other problem is that you are declaring and initialising a local variable array in your constructor; this variable has nothing to do with the member.

The same is true of your variable n. You keep redeclaring new, local variables that shadow the member variables.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...