lukassz lukassz - 9 days ago 6
C++ Question

Pass 2d vector to function using object no matching function error

I have problem with pass my

vector
to function in object.

Definition of my
vector


class PrintRectangle : public QWidget
{
Q_OBJECT
public:
explicit PrintRectangle(QWidget *parent = 0);

public:
teacher *tech;
bool clicked[5][5] = {};
std::vector<std::vector<perceptron>> p;
}


And implementation

PrintRectangle::PrintRectangle(QWidget *parent) : QWidget(parent),
p(5, std::vector<perceptron>(5))
{
tech = new teacher(clicked);

for(int i=0; i<5; i++)
{
for(int j=0; j<5; j++)
{
p[i][j].randweight();
}
}
double learnConst = 0.1;
tech->learnPerceptrons(p);
}


I get an error in
tech->learnPerceptrons(p);


E:\Sieci Neuronowe\Perceptron\printrectangle.cpp:20: error: no matching function for call to 'teacher::learnPerceptrons(std::vector<std::vector<perceptron> >&)'
tech->learnPerceptrons(p);
^


My function definition in
teacher
class

void learnPerceptrons(std::vector<std::vector<perceptron>> &p)


Where is the problem? Should I create object of
teacher
class in diffrent way?

All errors:

../../Sieci Neuronowe/Perceptron/printrectangle.cpp: In constructor 'PrintRectangle::PrintRectangle(QWidget*)':
../../Sieci Neuronowe/Perceptron/printrectangle.cpp:19:29: error: no matching function for call to 'teacher::learnPerceptrons(std::vector<std::vector<perceptron> >&)'
tech->learnPerceptrons(p);
^
In file included from E:/Sieci Neuronowe/Perceptron/printrectangle.h:6:0,
from ../../Sieci Neuronowe/Perceptron/printrectangle.cpp:1:
E:/Sieci Neuronowe/Perceptron/teacher.h:20:10: note: candidate: void teacher::learnPerceptrons(std::vector<std::vector<teacher::perceptron> >&)
void learnPerceptrons(std::vector<std::vector<perceptron>> &p);
^
E:/Sieci Neuronowe/Perceptron/teacher.h:20:10: note: no known conversion for argument 1 from 'std::vector<std::vector<perceptron> >' to 'std::vector<std::vector<teacher::perceptron> >&'
../../Sieci Neuronowe/Perceptron/printrectangle.cpp:17:12: warning: unused variable 'learnConst' [-Wunused-variable]
double learnConst = 0.1;
^
Makefile.Debug:833: recipe for target 'debug/printrectangle.o' failed
mingw32-make[1]: Leaving directory 'E:/nienazwany/build-nienazwany-Desktop_Qt_5_7_0_MinGW_32bit-Debug'
mingw32-make[1]: *** [debug/printrectangle.o] Error 1


and all code https://github.com/lukaszog/Perceptron

Answer

You mentioned in your post that:

My function definition in teacher class

void learnPerceptrons(std::vector> &p)

However, your teacher class on github has a method void learnPerceptrons(perceptron * (&array)[5][5]);, not learnPerceptrons(std::vector<std::vector<perceptron>> &p)....that must be the problem...

Comments