473,385 Members | 1,562 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,385 software developers and data experts.

structure required?

112 100+
i am working with a vector of pointers to Job class objects(job class is one that i defined)
when a person in my game dies, a pointer to the job he once had is added to a vector to track jobs that have no labor.

anyway when i try to use these they dont work

this is what i tried:

Expand|Select|Wrap|Line Numbers
  1.   for(int x =0;x<emptyJobs.size();x++)
  2.   {
  3.    string s = *emptyJobs[x].getName();
  4.    if(unemp.size()==0)
  5.     addNews("a(n) "+s+" has no labor.");
  6.   }
for some reason i get this from the compiler:
Expand|Select|Wrap|Line Numbers
  1. [C++ Error] Keep.cpp(57): E2294 Structure required on left side of . or .*
any suggestions as to what i am doing wrong??


thanks alot
ken
Nov 21 '07 #1
12 4596
scruggsy
147 100+
i am working with a vector of pointers to Job class objects(job class is one that i defined)
when a person in my game dies, a pointer to the job he once had is added to a vector to track jobs that have no labor.

anyway when i try to use these they dont work

this is what i tried:

Expand|Select|Wrap|Line Numbers
  1.   for(int x =0;x<emptyJobs.size();x++)
  2.   {
  3.    string s = *emptyJobs[x].getName();
  4.    if(unemp.size()==0)
  5.     addNews("a(n) "+s+" has no labor.");
  6.   }
for some reason i get this from the compiler:
Expand|Select|Wrap|Line Numbers
  1. [C++ Error] Keep.cpp(57): E2294 Structure required on left side of . or .*
any suggestions as to what i am doing wrong??


thanks alot
ken
The dot operator has higher precedence than the dereference operator.
So you need parentheses:
Expand|Select|Wrap|Line Numbers
  1.    string s = (*emptyJobs[x]).getName();
This is exactly why C++ has the indirection operator, ->.
You can rewrite the code as:
Expand|Select|Wrap|Line Numbers
  1.    string s = emptyJobs[x]->getName();
Nov 21 '07 #2
drsmooth
112 100+
now i fixed the code to both of the two ways and got the same exception:

this time at runtime:
---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class std::bad_alloc with message 'Exception Object Address: 0xF5BA42'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
Nov 22 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
Apparently you are using the new operator without try/catch blocks.

A bad_alloc usually means you have run out of heap memory.

A try/catch should allow you to see where the exception is being thrown.
Nov 22 '07 #4
drsmooth
112 100+
what would the catch bloc kcatch? i am familiar with try/catch from java but i dont know how the exceotions are written...

thanks,
ken
Nov 22 '07 #5
weaknessforcats
9,208 Expert Mod 8TB
C++ STL objects use a hierarchy for exceptions. The base class is exception. So you could catch that:

Expand|Select|Wrap|Line Numbers
  1. int* ptr = 0;
  2. try
  3. {
  4.      ptr = new int[100000];
  5. }
  6. catch( exception& err)
  7. {
  8.      cout << err.what() << endl;           //see what the error was
  9.      return;                                        //bail out of the function
  10. }
  11.  
The what() method returns a char* so you can use cout on it.

bad_alloc derives from exception so you could catch that also. The difference is that if you catch a bad_alloc you kow what you caught. Whereas with an exception, you don't know that. All you know is that itis some kind of exception.

You could have two catch blocks to differentiate:

Expand|Select|Wrap|Line Numbers
  1. int* ptr = 0;
  2. try
  3. {
  4.      ptr = new int[100000];
  5. }
  6. catch(bad_alloc& err)
  7. {
  8.      cout << err.what() << endl;           //see what the bad_alloc error was
  9.      return;                                        //bail out of the function
  10.  
  11. }
  12. catch( exception& err)
  13. {
  14.                                                        //not a bad_alloc
  15.      cout << err.what() << endl;           //see what the error was
  16.      return;                                        //bail out of the function
  17. }
  18.  
Nov 22 '07 #6
drsmooth
112 100+
i found the line where the exception was being throw from but th catch statement doesnt seem to be working

Expand|Select|Wrap|Line Numbers
  1.  //cycle through empty jobs and try to fill them
  2.   for(int x =0;x<emptyJobs.size();x++)
  3.   {
  4.    string s;
  5.    try{
  6.    s = (*emptyJobs[x]).getName();
  7.    }catch(exception& err){return;}
  8.  
  9.    if(unemp.size()==0)
  10.     addNews("a(n) "+s+" has no labor.");
  11.    else
  12.    {
  13. //*********************************************************************
  14.    }
  15.   }
  16.  }
thats what i have, when i step through the code the exception still causes the program to crash...?
Nov 23 '07 #7
weaknessforcats
9,208 Expert Mod 8TB
After your catch(exception&) block add a catch(...) block:
Expand|Select|Wrap|Line Numbers
  1. try
  2. {
  3.     //some code
  4. }
  5. catch(exception& err)
  6. {
  7.     //exception objects caught here
  8. }
  9. catch (...)
  10. {
  11.      //anything else caught here
  12. }
  13.  
If neither catch block catches the exception, then what you are calling an exception isn't an exception.

Let me know what you find.
Nov 24 '07 #8
drsmooth
112 100+
---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class std::bad_alloc with message 'Exception Object Address: 0xF5BA42'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------

this happens when i run this:

Expand|Select|Wrap|Line Numbers
  1.  //cycle through empty jobs and try to fill them
  2.   try{
  3.   for(int x =0;x<emptyJobs.size();x++)
  4.   {
  5.    string s;
  6.    s = (*emptyJobs[x]).getName();
  7.  
  8.    if(unemp.size()==0)
  9.     addNews("a(n) "+s+" has no labor.");
  10.    else
  11.    {
  12. //*********************************************************************
  13.    }
  14.   }
  15.   }catch(exception& err){return;}
  16.   catch(...){return;}
  17.  

..on a side note how do you get the code to be cpp instead of jus regualr code in the [CODE} tags?


thanks
Nov 24 '07 #9
weaknessforcats
9,208 Expert Mod 8TB
on a side note how do you get the code to be cpp instead of jus regualr code in the [CODE} tags?
Use code=cpp between the brackets of the tag.

Have you placed a breakpoint inside this try block to see of you are getting there. That bad_alloc could be somewhere else in the program.

If not, then do so and run the code using your debugger.
Nov 25 '07 #10
drsmooth
112 100+
well... i stepped through the code line by line from a break right before the try statement i showed above. i got to this line where the exception appears to happen:

Expand|Select|Wrap|Line Numbers
  1.    s = (*emptyJobs[x]).getName();
then i stepped through a gain and used 'evaluate/modify' to check the status of (*emptyJobs[x]).getName().

thats where it returned this:

E2122 Function call terminated by unhandled exception 0xeefface at address 0x7c812a5b

i checked what (*emptyJobs[x]) was and got this:

{ true, 1580, 1246764, 0, { :00000001, :0012FA40, { :00000111 } }, { :0013062C, :0012FA5C, { NULL } }, 20575260, 261, 1243872, 2118282740, { "k", "", { ",\x06\x13" } } }

i suppose that represents values stored in the class object?

my question now is what does:
E2122 Function call terminated by unhandled exception 0xeefface at address 0x7c812a5b
mean?
Nov 25 '07 #11
weaknessforcats
9,208 Expert Mod 8TB
And emptyJobs is a non-null pointer?? Right.

You can't dereference a null pointer.

If emptyJobs is OK as a pointer, then you may have to give me a bigger peek at your code. Expecially, the class declaration and the definition of the getName() method.
Nov 26 '07 #12
drsmooth
112 100+
the emptyJobs is pointer array which looks like this right before the error:

{ :00EAF718, :00EAF71C, { :00EAF71C } }

the get name function is defined as:

Expand|Select|Wrap|Line Numbers
  1. string Job::getName(){return jobName;}
jobName is defined here:
Expand|Select|Wrap|Line Numbers
  1. Job::Job(string x, int initialOffset)
  2. {
  3.   startDelay = initialOffset;
  4.   dataFile = "data\\jobs\\"+x+".dat";
  5.   analyzeDataFile();
  6.   hasWorker=true;
  7. }
if this is still not enough let me know. tonight i am going to try and drastically simplify the process here...i ended up with some superflous classes that i am going to try and weed out and maybe that will make this easier to correct...

thanks for all your help
Nov 26 '07 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Oliver Elphick | last post by:
The attached proposal is written primarily for Debian. Its motivation is that the current package upgrade process is pretty flaky and also that the current packaging does not really provide for...
15
by: damian birchler | last post by:
Hi I'm wondering of what type a structure is. Of course, it is a _structure_, but an array isn't an _array_ either. So of what type is a structure? I'd say a pointer, am I right?
3
by: ~~~ .NET Ed ~~~ | last post by:
Hello, I am having a problem trying to serialize this simple structure, I use it in a collection class that derives from CollectionBase but I noticed that at least for now the serialization...
14
by: Just Me | last post by:
Can anyone fix the code below? I need to set pTo to NULL and pFrom to a fullfilepath followed by two NULLs Below Filename is a string With FileOperation ..wFunc = FO_DELETE ..pFrom =...
3
by: Bob Simoneau | last post by:
I am trying to port a c structure for use in VB.NET. Note the char *target_name. I know it is just a 4 byte pointer, as I use PCHAR in delphi and it works. If I made it a pointer, how do a get...
18
by: jparus | last post by:
Hello, can anybody explain me how to port FILE structure into other languages. I have an DLL library and functions in this library take FILE* as a parameter. I want to make an interface into...
3
by: Zeke Zinzul | last post by:
Hi Guys & Geeks, What's the most elegant way of dealing with binary data and structures? Say I have this (which I actually do, a woo-hoo): struct Struct_IconHeader { byte width; byte...
5
by: Vibhesh | last post by:
I am facing problem with TimeSpan structure when DirectX is used. Following is the sample code that causes the problem: ...
17
by: Jason Doucette | last post by:
I am converting a C-style unit into a C++ class. I have an implementation function that was defined in the .cpp file (so it was hidden from the interface that exists in the .h file). It uses a...
25
by: jbholman | last post by:
I am pretty new to C and doing my first project in C. I actually read almost the entire FAQ, but can't seem to figure out this problem. I have a structure. I have a list of these structures. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.