Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

This is a snapshot of my code:

int m = 3;
int l = 4;
int k - 6;
std::vector<int> perceptrons;
for(int i = 0; i < k; i++){
    Perceptron Ki = Perceptron(m, l);
    perceptrons.push_back(Ki);
}

I get the following error:

Main.cpp:102:33: error: no matching function for call to       ‘std::vector<int>::push_back(Perceptron&)’
     perceptrons.push_back(Ki);

I have a class Perceptron that are objects with the parameters m and l also obviously, basically I'm just trying to create a Vector of perceptrons.

Can anybody see why this is?

Thanks

See Question&Answers more detail:os

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

1 Answer

Because you're trying to put a Perceptron into a vector of ints.

Change your code to:

int m = 3;
int l = 4;
int k - 6;
std::vector<Perceptron> perceptrons; // This is the line that needs changing
for(int i = 0; i < k; i++){
    Perceptron Ki = Perceptron(m, l);
    perceptrons.push_back(Ki);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...