Reputation: 859
#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?
Upvotes: 0
Views: 191
Reputation: 717
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.
Upvotes: 1