1

I've read visual studio 2012 adding new header file, but my problem has not been solved! Anyway, I want to add foo.h to my project:

#pragma once
void MyLDA(vector<int>, Mat_<float>, Mat&, Mat&);

Now, foo.cpp:

#include "stdafx.h"
#include "foo.h"

using namespace std;

auto getIndices = [](const std::vector<int>& vec, const int value)
{
//some code
}
void MyLDA(vector<int> gnd, Mat_<float> _data, Mat &eigvector, Mat &eigvalue)
{
//some code
}

when i build my project, i get this error:

'vector': undeclared identifier

type 'int' unexpected

'my_project': identifier not found

Miki
  • 40,887
  • 13
  • 123
  • 202
Saeid
  • 508
  • 1
  • 4
  • 20

1 Answers1

2

You need to #include <vector> to use std::vector. Also, best practice is to avoid using namespace std; and instead write std::vector. Some also recommend that for OpenCV classes such as Mat. (For what it’s worth, my own coding style is to write std:: in front of STL classes, since there’s a lot of legacy code out there with a custom string or array class, but to write cout and memcpy() rather than things like std::cout, for stuff that was around long before the STL.)

There’s also a missing semicolon after the assignment of a lambda expression, which happens to look a lot like a function definition at a glance. (@BarmakShemirani caught it, not me.)

Davislor
  • 14,674
  • 2
  • 34
  • 49