-3

I made an array wit a struct for example:

#include <opencv2/opencv.hpp>
#include "utils/Configuration.h"
#include <time.h>
using namespace std;
using namespace cv;    
struct plausibilitylinestruct{
        int x0;
        int y0;
        int x1;
        int y1;
        float p;
    } plausibilitylines[10];

How can I use member functions on the created array? C++ Refernce for array

I tried for example:

void addPlausibilitylines(vector<Vec4i> line) {
    if(plausibilitylines.empty()) {
        cout << "Test"<< endl;
    }
}

EDIT: I added some more code

Maksymal
  • 3
  • 2
  • 2
    What you have is a raw C array. It does not have any member functions. – DeiDei Jul 14 '17 at 11:14
  • `plausibilitylines.empty()` is invalid, since `plausibilitylines` is not an object. The reference you linked to is of `std::array`, which you are not using here. – Algirdas Preidžius Jul 14 '17 at 11:14
  • 1
    The reference you link to is for the *class template* `std::array`. What you're defining is a plain simple standard C-style array. Those two are different. I suggest you [find some good beginners books](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) to read. – Some programmer dude Jul 14 '17 at 11:19

1 Answers1

4

You simply confuse C-style array and std::array which was added since C++11.

C-style array obviously has no methods. In opposite, std::array is a container with its own set of methods.

To make use of std::array you have to convert your solution into something like:

std::array<plausibilitylinestruct, 10> plausibilitylines;

And then use methods like empty():

plausibilitylines.empty();
Edgar Rokjān
  • 17,245
  • 4
  • 40
  • 67
  • 1
    An std::array is empty if and only if it was constructed with size 0. I don't think that that's what the OP wants to archieve –  Jul 14 '17 at 11:28