0

I have the following structure declared in main (NEVERMIND THE MEMBERS!) :

struct args
{
    std::vector<string> names;
    std::vector<std::shared_ptr<RegularExpression>>vreg;
    std::vector<string> stopFile;
    std::vector<string> groundTruth;
    int debug;
};

and I have a classe Verification that takes args as a constructor parameter

#ifndef VERIFICATION_H
#define VERIFICATION_H

class Verification
{
    public:
        Verification(std::string, std::vector<double>,double,args);
    private:
         args _A; 

}
#endif // VERIFICATION_H

Now in main:

struct args
    {
        std::vector<string> names;
        std::vector<std::shared_ptr<RegularExpression>>vreg;
        std::vector<string> stopFile;
        std::vector<string> groundTruth;
        int debug;
    };
    int main()
    {
      Verification v("res.cr",gt, 0.75,A);
      return 0;
    }

I have the following compile errors :

  1. Verification.h|33|error: 'args' does not name a type| (this error is for the private member in the class _A)
  2. main.cpp|153|error: no matching function for call to 'Verification::Verification(const char [7], std::vector&, double, args&)'|
  3. Verification.h|24|error: 'args' has not been declared|(this error is the constructor)

How can I use the structure declared in main as a constructor parameter in class verification?

Thank you.

Hani Goc
  • 2,371
  • 5
  • 45
  • 89
  • 1
    Off-topic, but you shouldn't use [reserved names](http://stackoverflow.com/questions/228783) like `_A`. – Mike Seymour Nov 20 '13 at 12:24
  • Oh yeah? And stupid me I thought that i was doing the right thing lol. I had an inverview with a french company and in their code they did the same as I. I even asked them Why don't you have a constructor and a copy constructor, it's the rule of thumb in c++. She answered: NAAAAAAAAAAAAAA we don't need it. KILL ME – Hani Goc Nov 20 '13 at 14:35

3 Answers3

2

The structure must be defined in a way that it is visible to the Verification class translation unit. I suggest you move the struct to its own header file, and #include that in your main file and in Verification.h.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436
2

The first error is that when compiling class Verification the compiler must see struct args first. It doesn't know that you are gonig to define struct args later.

Simple fix would be to move the definition of struct args into Verification.h.

Fix that and you'll still have other errors though (most obviously that there's no definition for A), but we can deal with those when you get to them.

john
  • 85,011
  • 4
  • 57
  • 81
1

Your second error is due to the fact that a string literal is a const char[], not a std::string- you need to create a string before passing it to a function expecting a string.

Also, gt and A need to be defined before this call.

Hulk
  • 6,399
  • 1
  • 30
  • 52