M
magnus.moraberg
Hi, I have the following class -
#ifndef CASE_H_
#define CASE_H_
#include <QString>
#include <QStringList>
#include <QRegExp>
#include <QDir>
#include <stdexcept>
#include <iostream>
namespace FS
{
class Case
{
private:
QString name;
unsigned int version;
public:
...
friend std:stream& operator<<(std:stream& outStream, const Case&
case1);
};
}
#endif //CASE_H_
In my cpp file I include this function -
#include "Case.h"
using namespace FS;
....
std:stream& operator<<(std:stream& outStream, const Case& case1)
{
return outStream << case1.name.toStdString() << " v" <<
case1.version.toStdString();
}
However, this gives the error -
Case.h: In function ‘std:stream& operator<<(std:stream&, const
FS::Case&)’:
Case.h:27: error: ‘QString FS::Case::name’ is private
Case.cpp:50: error: within this context
Case.h:28: error: ‘unsigned int FS::Case::version’ is private
Case.cpp:50: error: within this context
Case.cpp:50: error: request for member ‘toStdString’ in ‘case1-
Does the friend not have access to the private members?
Thanks,
Barry.
#ifndef CASE_H_
#define CASE_H_
#include <QString>
#include <QStringList>
#include <QRegExp>
#include <QDir>
#include <stdexcept>
#include <iostream>
namespace FS
{
class Case
{
private:
QString name;
unsigned int version;
public:
...
friend std:stream& operator<<(std:stream& outStream, const Case&
case1);
};
}
#endif //CASE_H_
In my cpp file I include this function -
#include "Case.h"
using namespace FS;
....
std:stream& operator<<(std:stream& outStream, const Case& case1)
{
return outStream << case1.name.toStdString() << " v" <<
case1.version.toStdString();
}
However, this gives the error -
Case.h: In function ‘std:stream& operator<<(std:stream&, const
FS::Case&)’:
Case.h:27: error: ‘QString FS::Case::name’ is private
Case.cpp:50: error: within this context
Case.h:28: error: ‘unsigned int FS::Case::version’ is private
Case.cpp:50: error: within this context
Case.cpp:50: error: request for member ‘toStdString’ in ‘case1-
FS::Case::version’, which is of non-class type ‘const unsigned int’
Does the friend not have access to the private members?
Thanks,
Barry.