Okay. I am trying out using friend's, but not without some errors and confusion first. Here's how I've tried laying out these classes:
coord.h
Code:
#ifndef __COORD_H__
#define __COORD_H__
struct Coord
{
Coord(int a, int b) :
x(a), y(b) { }
int x, y;
};
#endif
And thingy.h
Code:
#ifndef __THINGY_H__
#define __THINGY_H__
#include <vector>
#include "coord.h"
#include "screen.h"
class Thingy
{
friend void Screen::add(const Thingy & t);
public:
Thingy();
virtual ~Thingy();
protected:
std::vector<Coord> v;
};
#endif
And screen.h
Code:
#ifndef __SCREEN_H__
#define __SCREEN_H__
#include "thingy.h"
#include <windows.h>
class Thingy;
class Screen
{
public:
Screen(int rows = 10, int cols = 10);
~Screen();
void paint(HWND hwnd);
void add(const Thingy & t);
protected:
private:
bool ** scr;
int rows;
int cols;
};
#endif
And finally screen.cpp
Code:
#include "screen.h"
//...
void Screen::add(const Thingy& t)
{
for(std::vector<Coord>::iterator i = v.begin(); i != v.end(); ++i);
}
//...
thingy.h gets an "error C2027: use of undefined type 'Screen'" pointing to the friend declaration. screen.cpp gets errors for v being undeclared. Any way I should rearrange things or declare things?