Reading an array through a pointer...

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
kadajett
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 66
Joined: Sun Apr 13, 2008 11:36 pm
Contact:

Reading an array through a pointer...

Post by kadajett »

Ok I have the problem that I need to use an array inside of a class pointer but I want to pass the whole array and make it into a temp array to render.

so here is what i have for main...

Code: Select all

#include <iostream>
#include "SDL.h"
#include "level.h"

//game loop stuff 
//rendering tiles and player
void render();

//handle controller 
void handleEvents();
//handle moving tiles and characters
void update();
//switch current level with new level
void changeLevel(level* newLevel);
//initialization
void init();

// is game running 
bool isRunning = 0;
//current playing level
level* currentLevel;

int main( int argc, char* args[] )
{
	isRunning = true;
	//main game loop
	while (isRunning)
	{
		handleEvents();
		update();
		render();
	}

	return 0;
}

 
//rendering tiles and player
void render()
{
	currentLevel->
}

//handle controller 
void handleEvents()
{

}

//handle moving tiles and characters
void update()
{

}

void changeLevel(level* newLevel)
{
	currentLevel = newLevel;
}

void init()
{
	level firstLevel;
	changeLevel(&firstLevel);
}
this is my level class

Code: Select all

#pragma once
#include <string>

class level
{
public:
	level(void);
	virtual ~level(void);
	void loadmap(std::string filname);
private:
	int map[10][10];
};
I hope you guys understand what I'm doing lol if not i will try to explain more :P
Image
DMan
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 1
Joined: Fri Jan 02, 2009 2:24 am

Re: Reading an array through a pointer...

Post by DMan »

//rendering tiles and player
void render()
{
currentLevel->
}

...

class level
{
public:
level(void);
virtual ~level(void);
void loadmap(std::string filname);
private:
int map[10][10];
};

Are you trying to access the map array inside the "currentLevel" instance of the level class?
In that case you might want to add an accessor function to the level class so that you can retrieve elements from the private 2d map array.

If that isn't what you are trying to do, could you provide more detail in your question?

-DMan
kadajett
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 66
Joined: Sun Apr 13, 2008 11:36 pm
Contact:

Re: Reading an array through a pointer...

Post by kadajett »

I just fixed it thank you anyways... I was going about it wrong lol I was trying to send all of my info into a render function when instead I should have had an individual render method for each level instance. That in turn made passing that array unnecessary... :P
Image
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Reading an array through a pointer...

Post by MarauderIIC »

Eh? I'm all for having a single 'renderer' class... Levels shouldn't render themselves, I think.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
ismetteren
Chaos Rift Junior
Chaos Rift Junior
Posts: 276
Joined: Mon Jul 21, 2008 4:13 pm

Re: Reading an array through a pointer...

Post by ismetteren »

MarauderIIC wrote:Eh? I'm all for having a single 'renderer' class... Levels shouldn't render themselves, I think.
I think too...
Image ImageImage Image
Post Reply