I have written simple class like below in file VRKVector.h
namespace vrk {
class VRKVector {
private:
std::vector<int> m_coordinates;
int m_dimension;
public:
/** VRKVector constructor.
* @param coordinates which represents a vector coordinates.
* @return none.
*/
VRKVector(std::vector<int> coordinates);
/** operator << : output stream operator
* @param out which is output stream we want to write
* @param vector which represents a vector coordinates.
* @return none.
*/
friend std::ostream& operator << (std::ostream& out, vrk::VRKVector& vrkvector);
};
}
VRKVector.cpp
// ============================================================================
// Local includes, e.g. files in the same folder, typically corresponding declarations.
#include "VRKVector.h"
// ============================================================================
// System includes, e.g. STL.
#include <iostream>
#include <fstream>
#include <sstream>
#include <iterator>
#include <algorithm>
// namespace declarations;
using namespace std;
using namespace vrk;
VRKVector::VRKVector(std::vector<int> coordinates) {
m_coordinates = coordinates;
m_dimension = coordinates.size();
}
std::ostream& operator<< (std::ostream& out, vrk::VRKVector& vrkvector) {
out << vrkvector.m_dimension;
return out; // return std::ostream so we can chain calls to operator<<
}
Above code I am getting error as shown below
1>C:\VRKVector.cpp(42,18): error C2248: 'vrk::VRKVector::m_dimension': cannot access private member declared in class 'vrk::VRKVector'
1>C:\\VRKVector.h(40): message : see declaration of 'vrk::VRKVector::m_dimension'
We can assess private member as we have friend function. Why am I seeing the error?