Lol_KekCheburek 0 / 0 / 0 Регистрация: 19.02.2017 Сообщений: 16 |
||||
1 |
||||
Передача вектора в функцию12.02.2018, 15:30. Показов 3340. Ответов 6 Метки нет (Все метки)
Как правильно передавать вектор в функцию?
0 |
Programming Эксперт 94731 / 64177 / 26122 Регистрация: 12.04.2006 Сообщений: 116,782 |
12.02.2018, 15:30 |
Ответы с готовыми решениями: Передача вектора в функцию void f(vector <int> v) в нее нужно передать… Передача вектора в функцию Передача вектора в функцию. #include <iostream> void show (); // ? int main () Передача вектора в функцию void foo(vector<int> &x) 6 |
║XLR8║ 1212 / 909 / 270 Регистрация: 25.07.2009 Сообщений: 4,361 Записей в блоге: 5 |
|
12.02.2018, 15:35 |
2 |
Lol_KekCheburek, на первый взгляд всё хорошо, только где std::? Нужно больше кода! (отсылка к Warcraft III)
0 |
Lol_KekCheburek 0 / 0 / 0 Регистрация: 19.02.2017 Сообщений: 16 |
||||
12.02.2018, 15:41 [ТС] |
3 |
|||
на первый взгляд всё хорошо, только где std::? Нужно больше кода! (отсылка к Warcraft III) В коде прописано using namespace std; Добавлено через 3 минуты
на первый взгляд всё хорошо, только где std::? Нужно больше кода! (отсылка к Warcraft III) Весь код. Задача отсортировать книг. В файле Books номера и название книги, я сортирую номера.
0 |
outoftime ║XLR8║ 1212 / 909 / 270 Регистрация: 25.07.2009 Сообщений: 4,361 Записей в блоге: 5 |
||||
12.02.2018, 15:47 |
4 |
|||
РешениеLol_KekCheburek, может хотябы ту строчку на которую указывает ошибка покажете? Добавлено через 1 минуту Добавлено через 2 минуты reverse(answer.begin(), answer.end()); //reverse vector Заголовочный файл <algorithm> Добавлено через 1 минуту
Порядок не тот.
0 |
Lol_KekCheburek 0 / 0 / 0 Регистрация: 19.02.2017 Сообщений: 16 |
||||||||||||
12.02.2018, 15:47 [ТС] |
5 |
|||||||||||
может хотябы ту строчку на которую указывает ошибка покажете? 1 ошибка:
2 ошибка:
3 ошибка:
0 |
outoftime ║XLR8║ 1212 / 909 / 270 Регистрация: 25.07.2009 Сообщений: 4,361 Записей в блоге: 5 |
||||
12.02.2018, 15:48 |
6 |
|||
Не используется
0 |
0 / 0 / 0 Регистрация: 19.02.2017 Сообщений: 16 |
|
12.02.2018, 15:51 [ТС] |
7 |
Порядок не тот. Благодарю, все заработало
0 |
What’s wrong with this line of code?
bar foo(vector ftw);
It produces
error C2061: syntax error: identifier 'vector'
bdonlan
223k30 gold badges266 silver badges323 bronze badges
asked Jun 11, 2010 at 22:04
Nick HeinerNick Heiner
118k187 gold badges474 silver badges698 bronze badges
try std::vector instead. Also, make sure you
#include <vector>
answered Jun 11, 2010 at 22:06
Adrian GrigoreAdrian Grigore
33k36 gold badges130 silver badges210 bronze badges
Probably you forgot to include vector and/or import std::vector
into the namespace.
Make sure you have:
#include <vector>
Then add:
using std::vector;
or just use:
bar foo(std::vector<odp> ftw);
answered Jun 11, 2010 at 22:06
Matthew FlaschenMatthew Flaschen
277k50 gold badges513 silver badges538 bronze badges
1
Do you have:
#include <vector>
and
using namespace std;
in your code?
<vector>
defines the std::vector
class, so you need to include it some where in your file.
since you’re using vector
, you need to instruct the compiler that you’re going to import the whole std
namespace (arguably this is not something you want to do), via using namespace std;
Otherwise vector should be defined as std::vector<myclass>
answered Jun 11, 2010 at 22:06
try std::vector<odp>
or using std;
answered Jun 11, 2010 at 22:06
TreDubZeddTreDubZedd
2,5511 gold badge15 silver badges20 bronze badges
On its own, that snippet of code has no definition of bar
, vector
or odp
. As to why you’re not getting an error about the definition of bar
, I can only assume that you’ve taken it out of context.
I assume that it is supposed to define foo
as a function, that vector
names a template and that it is supposed to define a parameter called ftw
but in a declaration anything that is not actually being defined needs to have been declared previously so that the compiler knows what all the other identifiers mean.
For example, if you define new types as follows you get a snippet that will compile:
struct bar {};
struct odp {};
template<class T> struct vector {};
bar foo(vector<odp> ftw);
answered Jun 11, 2010 at 22:07
CB BaileyCB Bailey
746k102 gold badges631 silver badges655 bronze badges
What’s wrong with this line of code?
bar foo(vector ftw);
It produces
error C2061: syntax error: identifier 'vector'
bdonlan
220k29 gold badges264 silver badges321 bronze badges
asked Jun 11, 2010 at 22:04
Nick HeinerNick Heiner
117k183 gold badges472 silver badges696 bronze badges
try std::vector instead. Also, make sure you
#include <vector>
answered Jun 11, 2010 at 22:06
Adrian GrigoreAdrian Grigore
32.8k36 gold badges130 silver badges209 bronze badges
Probably you forgot to include vector and/or import std::vector
into the namespace.
Make sure you have:
#include <vector>
Then add:
using std::vector;
or just use:
bar foo(std::vector<odp> ftw);
answered Jun 11, 2010 at 22:06
Matthew FlaschenMatthew Flaschen
274k50 gold badges513 silver badges537 bronze badges
1
Do you have:
#include <vector>
and
using namespace std;
in your code?
<vector>
defines the std::vector
class, so you need to include it some where in your file.
since you’re using vector
, you need to instruct the compiler that you’re going to import the whole std
namespace (arguably this is not something you want to do), via using namespace std;
Otherwise vector should be defined as std::vector<myclass>
answered Jun 11, 2010 at 22:06
try std::vector<odp>
or using std;
answered Jun 11, 2010 at 22:06
TreDubZeddTreDubZedd
2,5311 gold badge15 silver badges19 bronze badges
On its own, that snippet of code has no definition of bar
, vector
or odp
. As to why you’re not getting an error about the definition of bar
, I can only assume that you’ve taken it out of context.
I assume that it is supposed to define foo
as a function, that vector
names a template and that it is supposed to define a parameter called ftw
but in a declaration anything that is not actually being defined needs to have been declared previously so that the compiler knows what all the other identifiers mean.
For example, if you define new types as follows you get a snippet that will compile:
struct bar {};
struct odp {};
template<class T> struct vector {};
bar foo(vector<odp> ftw);
answered Jun 11, 2010 at 22:07
CB BaileyCB Bailey
732k101 gold badges625 silver badges651 bronze badges
- Remove From My Forums
-
Question
-
HI, thanks for the help.
I can’t use ‘vector’ in cli at all. I would like to make a vector of classes. I have the following code:
#include<cliextvector>
static vector<CEntry^>^ entry = gcnew vector<CEntry^>();
I get missing ‘;’ before ‘<‘ and missing type specifer — int assumed. Can you please help?
Thank you very much.
Answers
-
It’s in the cliext namespace:
static cliext::vector<CEntry^>^ entry =
gcnew cliext::vector<CEntry^>();
— Wayne- Marked as answer by
Wednesday, March 23, 2011 10:30 PM
- Marked as answer by
- Remove From My Forums
-
Question
-
HI, thanks for the help.
I can’t use ‘vector’ in cli at all. I would like to make a vector of classes. I have the following code:
#include<cliextvector>
static vector<CEntry^>^ entry = gcnew vector<CEntry^>();
I get missing ‘;’ before ‘<‘ and missing type specifer — int assumed. Can you please help?
Thank you very much.
Answers
-
It’s in the cliext namespace:
static cliext::vector<CEntry^>^ entry =
gcnew cliext::vector<CEntry^>();
— Wayne- Marked as answer by
Wednesday, March 23, 2011 10:30 PM
- Marked as answer by
I am having a C2061 error on the private methods on my classifier.h file. As you can see, I have #include vector, and i am using it for a public struct. Can someone please help me understand what I am overlooking?
#ifndef CLASSIFIER_H
#define CLASSIFIER_H
#include "patient_data.h"
#include <QObject>
#include <vector>
#include <stdlib.h>
class Classifier : public QObject
{
Q_OBJECT
public:
explicit Classifier(QObject *parent = 0);
~Classifier();
void classify(std::vector<patient_data>data, patient_data i);
struct CreateSDTable
{
std::vector<int>sum[3]; //element 0 = Tumor, element 1 = Stage, element 2 = Adjuvant
std::vector<long>mean[3];
std::vector<long>error[3];
std::vector<long>SDL[3];
std::vector<long>SD[3];
};
CreateSDTable CurrentvsNeutropenic;
CreateSDTable CurrentvsNonNeutropenic;
private:
std::vector<int> calculatesums(vector<patient_data> data, patient_data i, Neutropenic n);
std::vector<long> calculatemean(vector<int>validpatients, CreateSDTable Neut, CreateSDTable NonNeut);
std::vector<long>calculateerror(patient_data d, vector<int>m);
std::vector<long>calculatSDL(int nvp, CreateSDTable CVN, CreateSDTable CVsNN);
int NumofValidPatients(patient_data x);
I am having a C2061 error on the private methods on my classifier.h file. As you can see, I have #include vector, and i am using it for a public struct. Can someone please help me understand what I am overlooking?
#ifndef CLASSIFIER_H
#define CLASSIFIER_H
#include "patient_data.h"
#include <QObject>
#include <vector>
#include <stdlib.h>
class Classifier : public QObject
{
Q_OBJECT
public:
explicit Classifier(QObject *parent = 0);
~Classifier();
void classify(std::vector<patient_data>data, patient_data i);
struct CreateSDTable
{
std::vector<int>sum[3]; //element 0 = Tumor, element 1 = Stage, element 2 = Adjuvant
std::vector<long>mean[3];
std::vector<long>error[3];
std::vector<long>SDL[3];
std::vector<long>SD[3];
};
CreateSDTable CurrentvsNeutropenic;
CreateSDTable CurrentvsNonNeutropenic;
private:
std::vector<int> calculatesums(vector<patient_data> data, patient_data i, Neutropenic n);
std::vector<long> calculatemean(vector<int>validpatients, CreateSDTable Neut, CreateSDTable NonNeut);
std::vector<long>calculateerror(patient_data d, vector<int>m);
std::vector<long>calculatSDL(int nvp, CreateSDTable CVN, CreateSDTable CVsNN);
int NumofValidPatients(patient_data x);
I am having a C2061 error on the private methods on my classifier.h file. As you can see, I have #include vector, and i am using it for a public struct. Can someone please help me understand what I am overlooking?
#ifndef CLASSIFIER_H
#define CLASSIFIER_H
#include "patient_data.h"
#include <QObject>
#include <vector>
#include <stdlib.h>
class Classifier : public QObject
{
Q_OBJECT
public:
explicit Classifier(QObject *parent = 0);
~Classifier();
void classify(std::vector<patient_data>data, patient_data i);
struct CreateSDTable
{
std::vector<int>sum[3]; //element 0 = Tumor, element 1 = Stage, element 2 = Adjuvant
std::vector<long>mean[3];
std::vector<long>error[3];
std::vector<long>SDL[3];
std::vector<long>SD[3];
};
CreateSDTable CurrentvsNeutropenic;
CreateSDTable CurrentvsNonNeutropenic;
private:
std::vector<int> calculatesums(vector<patient_data> data, patient_data i, Neutropenic n);
std::vector<long> calculatemean(vector<int>validpatients, CreateSDTable Neut, CreateSDTable NonNeut);
std::vector<long>calculateerror(patient_data d, vector<int>m);
std::vector<long>calculatSDL(int nvp, CreateSDTable CVN, CreateSDTable CVsNN);
int NumofValidPatients(patient_data x);
Сам по себе этот фрагмент кода не имеет определения bar
, vector
или odp
. Что касается того, почему вы не получаете ошибку об определении bar
, я могу только предположить, что вы выбрали ее из контекста.
Я предполагаю, что он должен определять foo
как функцию, что vector
называет шаблон и что он должен определять параметр с именем ftw
, но в декларации ничего, что на самом деле не определено чтобы быть объявленным ранее, чтобы компилятор знал, что означают все другие идентификаторы.
Например, если вы определяете новые типы следующим образом, вы получите фрагмент, который будет компилироваться:
struct bar {};
struct odp {};
template<class T> struct vector {};
bar foo(vector<odp> ftw);