0
#include <QCoreApplication>
#include <vector>
#include <string>
#include <vector>
#include <QString>
#include <QVector>
#include <Method.h>

int main(int argc, char *argv[])
{

    QVector< QString> vec;

    QVector< QVector < QString> > mat;

    vector<string> vect;

    vector<vector<string> > matr;




    vec = Method::bogus(vect);

    mat = Method::bogusMa(matr);

}

#include <vector>
#include <string>
#include <vector>
#include <QString>
#include <QVector>
#include <Method.h>

using namespace::std;

QVector<QString> bogus(vector<string> & vec)
{
    QVector< QString > result;


    return result;

}

QVector<QVector <QString> > bogusMa(vector<vector<string> > & vec)
{

    QVector< QVector<QString> > result;


    return result;

}


#ifndef METHOD_H
#define METHOD_H

#include <vector>
#include <string>
#include <vector>
#include <QString>
#include <QVector>
#include <Method.h>

using namespace::std;

class Method{


public:
    static QVector<QString> bogus(vector<string> & vec);
    static QVector<QVector <QString> > bogusMa(vector<vector<string> > & vec);

};

#endif // METHOD_H

This is weird, because I don't get any error message when I am returning vectors containing anything else than QString. Sorry, if this sound like a dumb question, but I can't figure out exactly why I am getting this error. Does it have something to do with the include namespace statement in the header file? I don't see how those two might be connected. If it is the case, can you explain why it gives me an error?

2
  • Before we can help you, this error != NULL must be TRUE. Commented Apr 4, 2014 at 2:46
  • Just that there's no reference to what you mean by "this error" Commented Apr 4, 2014 at 12:35

1 Answer 1

1

When implementing a method, you need to specify the class there are in

QVector<QString> bogus(vector<string> & vec)

become

QVector<QString> Method::bogus(vector<string> & vec)

And

QVector<QVector <QString> > bogusMa(vector<vector<string> > & vec)

become

QVector<QVector <QString> > Method::bogusMa(vector<vector<string> > & vec)

The prototype for the method must also be included BEFORE its implementation, so you should move these after your class declaration.

Sign up to request clarification or add additional context in comments.

2 Comments

what if they are not in the same file (I have a header and a cpp file)?
In that case you need to include the header in the cpp file, and in the main (the "Method::" are still necessary in the cpp)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.