views:

230

answers:

4

i get this strange error while ruining my program with Visual C++ 2008 Express Edition:

'Ex2.exe': Loaded 'D:\studyMA\c++\visual studio\Ex2\Ex2\Debug\Ex2.exe', Symbols loaded.
'Ex2.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll'
'Ex2.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll'
'Ex2.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.30729.1_x-ww_f863c71f\msvcp90d.dll'
'Ex2.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.30729.1_x-ww_f863c71f\msvcr90d.dll'
First-chance exception at 0x1049615e in Ex2.exe: 0xC0000005: 
    Access violation reading location 0x333ee91c.
Unhandled exception at 0x1049615e in Ex2.exe: 0xC0000005: 
    Access violation reading location 0x333ee91c.
The program '[948] Ex2.exe: Native' has exited with code 0 (0x0).

class product looks like this:

 using namespace std; 

 class product
 { 
 public: 
     string Product_code;
     string Product_Name;
     string Product_Category;
     string Product_Vendor;
     string Product_Discription;
     string Product_Group;

    void input();
    void clear_product_cell();
 };

I have one more class (contained in bomba.h) which contains:

     product ProductList[100];

I've written code in bomba.cpp, asking the user for input:

 char ch;
 cout << "Please Select your option: ";
 cin >> ch;

 switch(ch)
   {
     case '1'://Add a product
     {
        ProductList[0].input();
             :
             :
        :

product.cpp looks like this:

 product::input()

     do{
     cout << "Please enter product code: ";
     getline(cin,Product_code);
     if (Product_code.empty())
      cout << "You Must Enter A Code!!!";
    } while(Product_code.empty());
    cout << endl;

In the console, I get:

Please Select your option: 1 Please enter product code:

...and when I type a number and after the number I type the CR key the program crashes and I get the errors I quoted above.

A: 

A 0xC0000005, or access violation, indicates that you are trying to access memory that doesn't belong to your process. This usually means you haven't allocated memory.

Unfortunately you have provided too little code to say where things are going wrong but my guess would be that Product_code is uninitialised.

Goz
+2  A: 

Without any information to go on ("Product_code is a member variable in class product" isn't very helpful), I'd guess that Product_code is null when you access it using .empty(), and that's causing the access violation. (I'm guessing based on the '0xC0000005' error code, but it is just a guess.)

Ken White
Null ? Probably not, unless a Product_code is supposed to be 800 MB-large.
RaphaelSP
"800 MB large"? Where did you get that? I didn't mention 800 MB in size anywhere in my answer, and the OP didn't mention it in the question. (Unless you're trying to use '0xC0000005' as a size, which it isn't; it's an error code. Google might be your friend.)
Ken White
@Ken: 0x333ee91c
sbi
@sbi: Great, except that's a memory address and not a size of any kind. Still doesn't explain RaphaelSP's comment. The Product_code member could easily have been assigned a memory address of 0x333ee91c, but that memory address was never initialized. Accessing it would result in accessing a null value, causing the access violation.
Ken White
BTW, you can easily tell it's a memory address and not a size specifier by looking at the error message itself: "location 0x333ee91c". Note the word "location".
Ken White
@Ken: I was just trying to point out where RaphaelSP might have that 800MB from, not necessarily defending his position. Please don't shoot the messenger! `:)`
sbi
RaphaelISP is quite right. Unless the object is 800 MB big, a NULL pointer error will not cause a fault at `0x333ee91c`.
MSalters
@sbi: No attempt to shoot intended. :-)
Ken White
By the way, I did not mean to be aggressive or rude by any means :-) - just a bit sarcastic. Although it is indeed a read access violation, it is more probably caused by reading in a code section or non-committed memory.
RaphaelSP
@MSalters: But a null member of an otherwise initialized object can (a member which is an object which isn't correctly initialized). Based on the code posted in the edit to the OP, I still think this is the case.
Ken White
@RaphaelSP: No offense taken. Just wasn't sure what you were intending to say. I don't see any indication that the address given referenced a size of any sort. It may be a misreference to a pointer that ended up at an address 8,000,000 bytes away from where it should have, but that's still just an invalid address reference and not a size. :-)
Ken White
A: 

what does Product_code look like after cin >> Product_code; ? it could be that Product_code.empty() is calling a function that doesnt exist because it is null

Scott M.
i solve the problem tnx anyway
Eitan
A: 

i solved the problem tnx anyway

Eitan
Would you edit your question - or answer - with some more details ?
RaphaelSP