I want to know how to fix xmemory0 errors.

I changed all the projects that I made yesterday.
The purpose of this project is to make food by receiving two ingredients just like the last time.
The last problem that occurred was solved and properly outputted.
The output is fine, but an error message is issued immediately after that.

The error message is as follows.

Debug Assertion Failed!

File: c:\program files (x86)\microsoft visual studio 14.0\vc\include\xmemory0
Line: 100
expression: "(_ptr_user & (_big_allocation_alignment -1 )) == 0" && 0
For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts.

I want to know how to fix xmemory0 errors.
Is this a memory problem?
Or is it because there's a problem with the code?

Thank you for your help and have a great day.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <string>
using namespace std;

class Ingredient {
	void ingre()
	{
	   cout << "Ingredient : ";
	}
protected:
	string a, b;
	string name[6] = { "apple", "eggs", "ham", "potato", "cheese", "tuna" };
	virtual string ing(string a, string b) = 0;
public:
	void run()
	{
		ingre();
		for (int i = 0; i < 6; i++)
			cout << name[i] << " ";
		cout << endl;
	}
	void Set()
	{
		cout << "Please enter your favorite ingredients (two) : ";
		cin >> a >> b;
	}
	void paint()
	{
		ing(a, b);
	}
};

class com :public Ingredient {
	string names[15] = { "pizza", "burger", "chopstick", "fried rice", "tuna soup", "egg with rice", "Gratin", "Cheese ball", "Tuna mayo rice bowl", "Potato croquette", "sandwitch", "rice with burger", "French fries", "potato soup", tuna Sashimi" };
protected:
	string ing(string a, string b)
	{
		if (a == name[0] && b == name[1])
			cout << names[0] << endl;
		else if (a == name[0] && b == name[2])
			cout << names[1] << endl;
		else if (a == name[0] && b == name[3])
			cout << names[2] << endl;
		else if (a == name[0] && b == name[4])
			cout << names[3] << endl;
		else if (a == name[0] && b == name[5])
			cout << names[4] << endl;
		else if (a == name[1] && b == name[2])
			cout << names[5] << endl;
		else if (a == name[1] && b == name[3])
			cout << names[6] << endl;
		else if (a == name[1] && b == name[4])
			cout << names[7] << endl;
		else if (a == name[1] && b == name[5])
			cout << names[8] << endl;
		else if (a == name[2] && b == name[3])
			cout << names[9] << endl;
		else if (a == name[2] && b == name[4])
			cout << names[10] << endl;
		else if (a == name[2] && b == name[5])
			cout << names[11] << endl;
		else if (a == name[3] && b == name[4])
			cout << names[12] << endl;
		else if (a == name[3] && b == name[5])
			cout << names[13] << endl;
		else if (a == name[4] && b == name[5])
			cout << names[14] << endl;
		else
			return 0;
	}
};

int main()
{
	Ingredient *d;
	d = new com;
	Ingredient *i = d; // Tried to Up-Casting

	d->run();
	d->Set();
	d->paint();

	i = d;
	delete i;
} 
Line 34, look at the last ingredient. No quotes to make it a string.
If the missing quote is fixed, there are more interesting problems:

(_ptr_user & (_big_allocation_alignment -1 )) == 0 && 0

So a pointer is likely misaligned.

The problem is on line 69. That 0 is treated as a null pointer when used to construct a string. Makes sense given the assertion failure above.
- Your base class requires a virtual destructor.
- Line 69 should read return "";
- Line 68 needs to be deleted so that the function always returns a value

I can't stress how important it is to use your tools to help you. Modern tools will diagnose a large fraction of problems in your code, if only you ask them to do so.

Both GCC and Clang identify these problems when asked:
http://coliru.stacked-crooked.com/a/a6891a660f14b832
Last edited on
Thanks you so much for catching my mistake on line 34. Furry Guy!
Ah, I didn't know if a virtual destructor was required.
Thank you for letting us know that you should delete row 68 so that it always returns a value.
Thank you very much for letting me know that there is such a good site. mbozzi!
Both of you have a nice day today.
I wish you a happy day.
Thanks you so much for catching my mistake on line 34.

You likely missed the problem because the line is so long horizontally, it scrolls off the right edge of the screen.

You can add some end-of-line whitespace, making easier to read without scrolling:

34
35
36
   string names[15] = { "pizza", "burger", "chopstick", "fried rice", "tuna soup",
                        "egg with rice", "Gratin", "Cheese ball", "Tuna mayo rice bowl", "Potato croquette",
                        "sandwitch", "rice with burger", "French fries", "potato soup", tuna Sashimi" }; 

The Grammar/Spelling Nazi in me rose up to loudly proclaim it is "sandwich," not "sandwitch." :)
Topic archived. No new replies allowed.