?
Solved

Need help with CPtrArray

Posted on 1998-05-07
2
Medium Priority
?
877 Views
Last Modified: 2012-06-27
I have written a socket server and client application that manages 22
different sockets at any given time.  Each socket is using the same server
address but has a different channel.  Two sockets have their own dedicated
pointers and then there are 20 data sockets that I open on the heap with the
same pointer name.  To keep track of those 20 data pointers I am trying to use
a CPtrArray to hold them.  I don't get any compile or run-time errors, but the array
is not being loaded with the socket pointers.

CPtrArray pDataSockArray;
pDataSockArray.SetSize(MAX_DATA_CLIENTS,-1);

CDataSocket* pDataClient;
pDataClient = new CDataSocket;
pDataSockArray.SetAt(0, pDataClient);

This does not work.  I looked at the example in ChatSrvr
on MSDN and it uses a CPtrList.  I need to be able to access
the pointers by index not sequentially.  What am I doing wrong?
Is there a better way?

Help    -- jr
0
Comment
Question by:jrmcg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 10

Accepted Solution

by:
RONSLOW earned 300 total points
ID: 1174310
What do you mean by "not being loaded with the socket pointers"?

Have you set a break point to ensure that the SetAt is happening?

And shouldn't that be SetAtGrow (so you don't overflow the array).

Also, you are better off using the CArray template class as that way you don't loose type info by the casting to void* that CPtrArray does.


0
 
LVL 2

Author Comment

by:jrmcg
ID: 1174311
Thanks - I corrected the SetAt call, I found that it was working correctly
but I had the call in the wrong place.  I am going to look into the CArray
template class.  That does seem to be a better option.

-- jr
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question