Okay this feels like a really silly question. Values that I have set to private should be able to be used through out that class alone, yeah. Say I have this:

#include <iostream>
using namespace std;

class Telegram{

public:
	Telegram();

	~Telegram();

	void getData();


private:
	int **telegram;
	int rows, cols; 
};
#include <iostream>
#include "Telegram.h"
using namespace std;


 Telegram::Telegram(){
		rows = 32;
		cols = 8;
		dataCounter = 0; //keep track of how many times setData is called
		telegram = new int *[rows];
		//initalized telegram array and sets values to 0 by default
		for(int i = 0; i < rows; i++)
		{
			telegram[i] = new int[rows];
		}
		for(int i = 0; i < rows; i++)
		{
			for(int j = 0; j < cols; j++)
			{
				telegram[i][j] = 0;
			}
		}
	}

	Telegram::~Telegram(){
		for(int i = 0; i < rows; i++){
			delete[] telegram[i];
		}
		delete[] telegram;
	}

	void Telegram::getData(){
		for(int i = 0; i < rows; i++){
			for(int j = 0; j < cols; j++){
				cout << telegram[i][j];
			}
		cout << "\n";
		}
	}
#include <iostream>
#include "Telegram.h"
using namespace std;

class SSBL{

public:
	SSBL();

	~SSBL();

	void print();

private:
	Telegram *tele;
};
#include <iostream>
#include "SSBL.h"
using namespace std;


SSBL::SSBL(){
	//create new telegram object
	Telegram *tele = new Telegram();
}

SSBL::~SSBL(){
}

void SSBL::print(){
	tele->getData();
}
#include "SSBL.h"

int main(){
	SSBL *test = new SSBL();
	test->print();
	
}

this is a simplified version of my code, the removed functions shouldn't effect anything. When I step through the program I noticed that the values for the variables I have set to private aren't carrying through. So when it gets to getData() those values are ??? and it breaks.

Your SSBL constructor is creating a new local Telegram object called tele that hides the private member called tele. So you're not actually initializing the private member at all.

-delete- sorry, brain fart

thanks for the help, I see what you mean now

Change Telegram *tele = new Telegram(); to tele = new Telegram(); in the SSBL constructor.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.