Cannot access private member declared in one class BUT I can in another class

Pages: 12
Why, what would that do? That is also an error "expected a ;"
Could you please paste the updated code that is generating that error and also copy and paste the exact error message?
Last edited on
Sure.
So here is Engine.h,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#pragma once
#include "stdafx.h"
#include "SFML/Graphics.hpp"
#include "ImageManager.h"
#include "Board.h"
#include <iostream>
#include "Box.h"

class Engine{
public:
	Engine();
	~Engine();

	void Go();
private:
	void ProcessInput();
	void Update();
	void Render();

	void FillVector();

	ImageManager imgr;
	Board board{imgr};

	sf::Sprite gameBoard;

	sf::RenderWindow window;
	sf::Event event;
};
and doing what you said in your last post, Board board{imgr} throws an error "expected a ;". In case the both of us may have gotten lost in these problems, my goal is to have one instance of an ImageManager object, and I want Board among other classes to have full access to it. How do I pass the ImageManager imgr, that is stated above, along to other classes?
If your compiler does not support C++11, you will need to change line 23 to this:

Board board;

And then in your Engine constructor initialize it like this:
1
2
3
4
5
6
7
Engine::Engine
: board(imgr)
, exampleMember2(blah)
, exampleMember3(meh)
{
    //...
}
Ideally though you should research how to enable C++11 for your compiler.
@LB Thank you so much for all your help! You're much more helpful than any tutorial (and much more patient). So in short, if I want to pass around an instance of an object, I want to do something like Example::Example : class(object){ }, then receive the object like Class::Class(&obj) : object(obj){ }, got it. Thanks again.
One last question, and I suppose this is for anybody, is the method described above an efficient one in terms of speed and convention?
Passing by reference is efficient for anything larger than primitive types ;)
Topic archived. No new replies allowed.
Pages: 12