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
984 views
in Technique[技术] by (71.8m points)

push_back in the vector class in C++

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

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

1 Reply

0 votes
by (71.8m points)

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

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

...