Error Debug Assertion Failed!

Pages: 123
Thomas,

I would like to try to figure out why this statement is causing an error: m_Filters.SetSize(1);

If I can do this: m_Filters.Add(filter), then it seems that I should be able to SetSize. The description of SetSize is pretty simple.

I might not be very good at C++, but my programming sense tells me that if I am going to set the size of an array to 1, then that must mean I don't care about what is in that array, since I am reducing it's size to 1.

If that is the case, there should be a way to initialize the array to being empty or having no elements.

It doesn't make sense that a simple statement to reduce the size of an array should cause an error that nobody can figure out.

Do you have any idea of what would cause this problem?

Thanks,
Tony
Tony,

I think the problem has nothing to do with CArray. I created a simple console app and tested it and it works as expected.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
CArray<int> numbers;
wprintf(L"\nOriginal size of the array: %d", numbers.GetSize());
wprintf(L"\nAdding to 2 numbers to the array");
numbers.Add(1);
numbers.Add(2);
wprintf(L"\nThe numbers are:");
for (int i = 0; i < numbers.GetSize(); i++)
{
  wprintf(L"\nNum[%d] = %d", i, numbers[i]);
}
wprintf(L"\nResizing the array to 1");
numbers.SetSize(1);
wprintf(L"\nThe only number is: ");
wprintf(L"%d\n\n\n", numbers[0]);

My guess is that the problem is in the CMailFilter class. Maybe you can extract the code and test it in a separate program - maybe with a std::vector as well.
Thomas,

Thanks for doing that test. That proves that SetSize works. It's just not working with the CMailFilter type. Is that what you are telling me?

I'm not sure of how I would put CMailFilter in a test program and use it. I don't know what I would do to test it. Would I just create an object of CMailFilter and try to add it to an array?

I'm not sure.

Thanks,
Tony
Things get even more mysterious. I did a separate test and it seems to work.
Have a look.
https://www.dropbox.com/sh/rgp6e3c8iiaspo5/AABawKD-LkFMh7r4nzhUYhuwa?dl=0
Thomas,

Thank you for this excellent test. I'm not sure of why you think it is mysterious. I'm not saying it is not mysterious. I just don't know.

I would like to know if you agree with my comments about this code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
int main()
{
  CArray<CMailFilter, CMailFilter&> filters;
  
  filters.SetSize(1);			//Enters then leaves the default constructor
  
  CMailFilter filter, filter2(filter);	// "filter2(filter)" creates a new object as a copy of an existing object
				        // Enters then leaves the default constructor
				        // then enters the copy constructor
				        // then enters assignment operator
				        // then leaves the assignment operator
				        // then leaves the copy constructor
  
  filters[0] = filter;			// Enters then leaves the assignment operator
  
  filters.Add(filter2);			// Enters then leaves the default constructor
					// Enters then leaves the assignment operator

  system("pause");
  return EXIT_SUCCESS;
}


Can you explain what it is you are trying to point out besides the fact that it works?

Thanks,
Tony
Last edited on
Hi Tony,

mysterious in the way that it suddenly worked. In the beginning it crashed when you tried to use SetSize. Now you know that the problem was not in the CArray nor in the CMailFilter class.
Topic archived. No new replies allowed.
Pages: 123