简体   繁体   中英

Constructor: function does not take 3 arguments

Why the lines "nota(sinais, subs, indices);" tells that function does not take 3 arguments. I've defined a constructor with 3.

class Solucao{
        bool    *sinal;
        bool    *sublinhado;
        int     *indice;
public:
        Solucao(){sinal = sublinhado = NULL;  indice = NULL; };
        Solucao (bool *sinais, bool *subs, int *indices)
        {
            sinal = sinais;
            sublinhado = subs;
                indice = indices;
        };
};


void Balas(int n, int m, Vector<float> c, Vector<float> b, Matrix<float> A) {
No_Balas *J = NULL;
Solucao *nota();
bool *sinais = new bool[1];
bool *subs = new bool[1];
int *indices = new int[1];

Vector<int> pto_inicial(1);

    pto_inicial[0] = 0; 
    sinais[0] = 0;
    subs[0] = 0;
    indices[0] = 0;

nota(sinais, subs, indices);
}

The nota instance has a Solucao* type (ie, it's a pointer -- I assume the extra parenthesis are a typo and that you weren't trying to declare a function) as opposed to a Sulucao type.

Based on your current code it seems like you're trying to do the following:

nota = new Solucao(sinais, subs, indices);

However, I'd probably recommend against using new unless you have a good reason to do so. Instead you could remove the Solucao *nota(); and just construct it once you have all the required parameters:

Solucao nota(sinais, subs, indices);

Note: If you continue to use dynamic allocation (ie, new ) I'd recommend you use a C++11 compliant compiler and learn about the available smart pointers. For example:

std::unique_ptr<Solucao> nota = std::make_unique(sinais, subs, indices);
Solucao *nota();

This declares a function named nota that takes no arguments and returns a pointer to Solucao . So the compiler is right that it doesn't take 3 arguments.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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