Меню

Синтаксическая ошибка идентификатор vector

What’s wrong with this line of code?

bar foo(vector ftw);

It produces

error C2061: syntax error: identifier 'vector'

bdonlan's user avatar

bdonlan

220k29 gold badges264 silver badges321 bronze badges

asked Jun 11, 2010 at 22:04

Nick Heiner's user avatar

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 Grigore's user avatar

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 Flaschen's user avatar

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

Alan's user avatar

try std::vector<odp> or using std;

answered Jun 11, 2010 at 22:06

TreDubZedd's user avatar

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 Bailey's user avatar

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

  • 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

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

0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии

А вот еще интересные материалы:

  • Яшка сломя голову остановился исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного где ошибка
  • Синтаксическая ошибка параметр не инициализирован
  • Синтаксические ошибки это определение