Putting an object to the problem in the structure [April 26, 2004 9:27]

zhaozj2021-02-16  67

I am doing a data forwarding, I originally requested to use BCB to make a come out. BCB has made it, it feels very fun, so I have done it again with VC. Of course, BCB and VC think that most of them are not the same. Now I want to expand, use VC to make a service program, you can dynamically apply for an open port (original just a service port). Specifically, let's talk again!

Let's put Carray in the structure,

Typedef struct tagmainservice

{

Tchar disabledaddr [30];

Carray

ArrsubService;

} Mainservice, * lpmainservice;

then

Mainservice m;

Subservice s;

M.arrsubService.Add (s);

In this way, there should be no problem! There is no problem.

But today, I use it when I jump out of my 莫 其 debug error. And it is where I first called ArrsubService. Stopwing place

1. Add

2. Assert_Valid (this);

2. Assert (nindex> = 0); // stop here

3. AfxassertValidObject

See NINDEX> = 0 first, this is obvious! How can I get here? I can't understand for a long time. Tell nonsense, or I really want to reveal it immediately. I used MEMSET functions many times in the program. How does the structural body do not need MEMSET! I believe that the master should see anything to come! MEMSET clears the initialization of the Carray object, huh, although it is an object, it will not find this with New. Above, the VC is really broken should be Assert (this).

The reason is found, to solve it, but also

Carray

ArrsubService;

Changed to Carray

* ParrsubService;

Memset previously remembered the ParrsubService clear. If you want to save the data inside Carray, you can take over with a temporary Carray pointer, then Memset, then refer to it, pay attention to put parmayold = null, otherwise the architecture of Array is gone. Use the first New. In this way, the new problem has come out.

M_mainService.arrsubService [i]. Disabledaddr

It turned out that the above sentence is directly available. Now when [i] is out, you can see the function of the VC prompt carray, but the compilation is not. Think about it, it should be a problem that ArrsubService is converted into a pointer. Generally we use

Char * p = new char [100];

P [10] = 'a';

This will not have problems, Carray and this convention reverse, modify

(* m_mainservice.arrsubservice) [i]. Disabledaddr

Oh, it's okay.

转载请注明原文地址:https://www.9cbs.com/read-17204.html

New Post(0)