473,405 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Me again with same problem.

It is me again with the same problem with my game. I can get data from
one object to another.
I have my player play graphic stored in a vector. I would like to get
that data out of tha object and display my graphics in the part that
displays the graphics. I have made significant changes in my program
but I can't get it to work.

class space{
char gchar;
graphic *gr;
graphic *grDefault;
graphic *cgr;
player * play;
bool seen;

graphic& space::graphicOut(){

if(play){
vector<BYTE>t;
play->data(t);
cgr = new graphic(t);
return *cgr;
}
//if(play){return *cgr;}
if(seen){return *gr;}
else {return *grDefault;}
}

void data(vector<BYTE>& d){
for(int lp = 0; lp != 32; lp++){
//d.push_back(gData[lp]);
}
}

I have been trying many thing to make this work I down't understand why
I can't return the graphics vector or the individual datas to retrun
out of this object.

May 28 '06 #1
6 1535
* JoeC:
It is me again with the same problem with my game. I can get data from
one object to another.
I have my player play graphic stored in a vector. I would like to get
that data out of tha object and display my graphics in the part that
displays the graphics. I have made significant changes in my program
but I can't get it to work.

class space{
char gchar;
graphic *gr;
graphic *grDefault;
graphic *cgr;
player * play;
bool seen;

graphic& space::graphicOut(){

if(play){
vector<BYTE>t;
play->data(t);
cgr = new graphic(t);
return *cgr;
}
//if(play){return *cgr;}
if(seen){return *gr;}
else {return *grDefault;}
}

void data(vector<BYTE>& d){
for(int lp = 0; lp != 32; lp++){
//d.push_back(gData[lp]);
}
}

I have been trying many thing to make this work I down't understand why
I can't return the graphics vector or the individual datas to retrun
out of this object.


Your code is hard to follow, that's probably what's makes it hard to create.

Split the problems into smaller, more well-defined problems.

When a problem is well-defined it is much easier to solve.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 28 '06 #2
Sorry, I got fustrated and careless in my attempts to make this work.

I made some changes that should work but my program crashes.

class player{
string name;
vector<BYTE>gData;
void create();

public:
player();
BYTE data(const int);
void dummy(){MessageBox(NULL, "Dummy" , "Notice", MB_OK); }
};

BYTE player::data(const int n){return gData[n];}

class space{

player * play;
.....

graphic& space::graphicOut(){

if(play){
vector<BYTE>t;
for(int lp = 0; lp != 32; lp++){
t.push_back(play->data(lp));
}
cgr = new graphic(t);
return *cgr;
}
//if(play){return *cgr;}
if(seen){return *gr;}
else {return *grDefault;}
}

What I am trying to do is read the vector from my player into a new
vector in my graphicOut function. My problem is my program keeps
crashing when I try to get data from my player object.

May 29 '06 #3

"JoeC" <en*****@yahoo.com> wrote in message
news:11*********************@y43g2000cwc.googlegro ups.com...
Sorry, I got fustrated and careless in my attempts to make this work.

I made some changes that should work but my program crashes.

class player{
string name;
vector<BYTE>gData;
void create();

public:
player();
BYTE data(const int);
void dummy(){MessageBox(NULL, "Dummy" , "Notice", MB_OK); }
};

BYTE player::data(const int n){return gData[n];}

class space{

player * play;
....

graphic& space::graphicOut(){

if(play){
vector<BYTE>t;
for(int lp = 0; lp != 32; lp++){
t.push_back(play->data(lp));
}
what is play->data(lp) supposed to be giving you? It would be nice if you
actually showed us what BYTE data( const int); was doing, as that's where
your problem might be.
Also, what is BYTE defined as? I could presume unsigned char, but I might
be presuming wrong.

How do you know how much data the vector? Are there actually 32 values?
Are you sure? How do you know? How do we know?

Why do you need to copy it anyway? Why don't you just return a pointer or a
reference to it?
cgr = new graphic(t);
return *cgr;
}
//if(play){return *cgr;}
if(seen){return *gr;}
else {return *grDefault;}
}

What I am trying to do is read the vector from my player into a new
vector in my graphicOut function. My problem is my program keeps
crashing when I try to get data from my player object.

May 29 '06 #4
* JoeC:
Sorry, I got fustrated and careless in my attempts to make this work.

I made some changes that should work but my program crashes.

class player{
string name;
vector<BYTE>gData;
void create();

public:
player();
BYTE data(const int);
void dummy(){MessageBox(NULL, "Dummy" , "Notice", MB_OK); }
};

BYTE player::data(const int n){return gData[n];}

class space{

player * play;
....

graphic& space::graphicOut(){

if(play){
vector<BYTE>t;
for(int lp = 0; lp != 32; lp++){
t.push_back(play->data(lp));
}
cgr = new graphic(t);
return *cgr;
}
//if(play){return *cgr;}
if(seen){return *gr;}
else {return *grDefault;}
}

What I am trying to do is read the vector from my player into a new
vector in my graphicOut function. My problem is my program keeps
crashing when I try to get data from my player object.


There are many possible technical reasons, including (1) 'play' is a
bogus pointer, (2) play->gData doesn't currently hold 32 items or more,
(3) the 'graphic' constructor fails.

Starting with (1), your original post indicated that class 'space' does
not have any constructor defined by you (although as shown in that post
the class would have all members private and be unusable, so it could
not be real code: please consult the FAQ about how to post examples).
The default constructor supplied by the compiler doesn't initialize the
non-class type members, and all your members are non-class type. Thus,
the probability of a bogus 'play' pointer is quite high.

To reduce the probability of that sort of thing happening, make all the
class data members private, if they aren't already, and make sure to
initialize them all in every constructor you define. Also keep in mind
that when you have pointer members, you need to either use
smart-pointers or take manually charge of copying or disable copying.
The simplest is to disable copying: declare a private copy constructor
and a private assignment operator, and simply don't define them.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 29 '06 #5
what is play->data(lp) supposed to be giving you? It would be nice if
you
actually showed us what BYTE data( const int); was doing, as that's
where
your problem might be.
Also, what is BYTE defined as? I could presume unsigned char, but I
might
be presuming wrong.

BYTE pgr[] = {0xfc,0x3d,0xf8,0x1d,0xf8,0x1d,0xfc,0x3d,
0xfe,0x7d,0xf0,0x18,0xe8,0x0d,0x8c,0x31,
0x0c,0x3f,0x0c,0x3f,0x0b,0xdf,0x9b,0xdf,
0xfb,0xdf,0xfb,0xdf,0xfb,0xdf,0xf3,0xcf};

for(int lp = 0; lp != 32; lp++)
gData.push_back(pgr[lp]);
}

How do you know how much data the vector? Are there actually 32
values?
Are you sure? How do you know? How do we know?

Yes, all my data has 32 numbers. A BYTE is what I need to create data,
it is built into the windows.h library.

Why do you need to copy it anyway? Why don't you just return a pointer
or a
reference to it?

I don't think I have tried that how would that work with a vector?

May 29 '06 #6
class space{
char gchar;
graphic *gr;
graphic *grDefault;
graphic *cgr;
player * play;
bool seen;

public:
space();
~space();
void graphicIn(char g);
graphic& graphicOut();
void playIn(player*);
bool isPlay();
void see(){seen = true;}
bool been(){return seen;}
void playOut();
bool canMove();
bool winspace();
};

space::space(){
play = 0;
grDefault = new graphic();;
seen = false;
}

later I put the player in:

void space::playIn(player *p){
play = p;
seen = true;
}

Here is my space constructor, how can I make it better?

The point of using pointers is that I want one player to be moved from
space to space, I don't want each space to have a player but the
potential to hold one. This concept actually worked with a simikkiar
program where I returned a character in stead of a an object. It
worked fine.

..To reduce the probability of that sort of thing happening, make all
the
..class data members private, if they aren't already, and make sure to
..initialize them all in every constructor you define.

Which class, the player.

..Also keep in mind
..that when you have pointer members, you need to either use
..smart-pointers or take manually charge of copying or disable copying.
..The simplest is to disable copying: declare a private copy constructor
and a private assignment operator, and simply don't define them.
so play = p, I need a copy constructor or do I need an assignment (=)?
This could be my problem.

Here is player:

I would appreeciate tips, if you have time.

class player{
string name;
vector<BYTE>gData;
void create();

public:
player();
player(const player&) ; <-to add
BYTE& data();
void dummy(){MessageBox(NULL, "Dummy" , "Notice", MB_OK); }
};

player::player(){
name = "";
create();
}

void player::create(){

BYTE pgr[] = {0xfc,0x3d,0xf8,0x1d,0xf8,0x1d,0xfc,0x3d,
0xfe,0x7d,0xf0,0x18,0xe8,0x0d,0x8c,0x31,
0x0c,0x3f,0x0c,0x3f,0x0b,0xdf,0x9b,0xdf,
0xfb,0xdf,0xfb,0xdf,0xfb,0xdf,0xf3,0xcf};

for(int lp = 0; lp != 32; lp++)
gData.push_back(pgr[lp]);
}

BYTE player::data(const int n){return gData[n];}

I am going to work on the ideas you gave me I think you have come
pretty close to telling me what my problem is. That does make sence.

Originally I had the player create a graphic class and then just return
it and I have been fiddeling with this program for a while. But the
purpsoe of what I do is learning.

Thanks, I hope I have time to inoperate the changes soon.
My cable went out but here is what I added:

player::player(const player& pl){
name = pl.name;
gData = pl.gData;
}

player& player::operator =(const player& pl){
if(&pl != this){
name = pl.name;
gData = pl.gData;
}
return *this;
}

It still crashes at this point:

graphic& space::graphicOut(){

if(play){
vector<BYTE>t;
for(int lp = 0; lp != 32; lp++){
//t.push_back(play->data(lp));
}
cgr = new graphic(t);
return *cgr;
}
//if(play){return *cgr;}
if(seen){return *gr;}
else {return *grDefault;}
}

I am just trying to get it to work and later I want to make it better.

May 29 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: jon morgan | last post by:
OK, I'm going to be brave. There is a bug in VS.Net 1.1 that causes random compiler errors. I have raised this issue in posts at least three time in the past couple of months without attracting...
17
by: Gabriel Mejía | last post by:
Services or applications using ActiveX Data Objects (ADO) 2.0 or greater may intermittently return empty recordsets on queries that should be returning valid results. At the time the problem...
11
by: Steven T. Hatton | last post by:
In the past there have been lengthy discussiions regarding the role of header files in C++. People have been very adamat about header files serving as in interface to the implementation. I do...
4
by: Jerry Krinock | last post by:
I've written the following demo to help me understand a problem I'm having in a larger program. The "main" function constructs a Foo object, and then later "reconstructs" it by calling the...
13
by: NM | last post by:
Sometimes ago I was having a problem in linking between C++ and Fortran program. That was solved (using input from this newsgroup) using the Fortran keyword "sequence" with the derived types (to...
16
by: junky_fellow | last post by:
According to Section A6.6 Pointers and Integers (k & R) " A pointer to one type may be converted to a pointer to another type. The resulting pointer may cause addressing exceptions if the...
0
by: DANIEL HENEGHAN | last post by:
From Norm Matloff's newsletter To: H-1B/L-1/offshoring e-newsletter Any time you see a bunch of newspaper and magazine editorials that call on Congress to raise the H-1B, you can count on more...
39
by: Martin Jørgensen | last post by:
Hi, I'm relatively new with C-programming and even though I've read about pointers and arrays many times, it's a topic that is a little confusing to me - at least at this moment: ---- 1)...
3
by: Sandeep Singh Sekhon | last post by:
I am developing an application in ASP.NET 1.1. on one page I allow the user to upload and delete the files to the server. When I delete the file, I physically delete the file from the location....
29
by: wizofaus | last post by:
I previously posted about a problem where it seemed that changing the case of the word "BY" in a SELECT query was causing it to run much much faster. Now I've hit the same thing again, where...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.