Click here to Skip to main content
15,899,549 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
General[WinInet] Retrieving error info from FTP Pin
Marcelo N. Magri29-Jan-03 1:07
Marcelo N. Magri29-Jan-03 1:07 
GeneralRe: [WinInet] Retrieving error info from FTP Pin
Ben Burnett29-Jan-03 10:46
Ben Burnett29-Jan-03 10:46 
Generalpassing CArray in functions Pin
r i s h a b h s29-Jan-03 0:02
r i s h a b h s29-Jan-03 0:02 
GeneralRe: passing CArray in functions Pin
jhwurmbach29-Jan-03 1:33
jhwurmbach29-Jan-03 1:33 
GeneralRe: passing CArray in functions Pin
HENDRIK R29-Jan-03 2:38
HENDRIK R29-Jan-03 2:38 
GeneralRe: passing CArray in functions Pin
r i s h a b h s29-Jan-03 17:31
r i s h a b h s29-Jan-03 17:31 
GeneralRe: passing CArray in functions Pin
HENDRIK R29-Jan-03 21:40
HENDRIK R29-Jan-03 21:40 
GeneralRe: passing CArray in functions Pin
Alvaro Mendez29-Jan-03 4:07
Alvaro Mendez29-Jan-03 4:07 
You need to decide if the function will have read/write access to the array or just read access to it.

If it's going to have read/write access, you would just pass it by reference or pointer. By reference is easier since you can use the value semantics (dot notation), however I prefer to pass by pointer since it becomes more obvious that the function is going to change the array.

If it's only going to read the array, then the best way is to pass it by const reference. This gives you the benefits of value semantics while ensuring the array won't be changed (at least not without some ugly casting).

I also recommend creating an alias for the CArray< TASKS, TASKS& >, to make it easier to read (and write). You do that with typedef:

typedef CArray< TASKS, TASKS& > TaskArray;

rishabhs wrote:
1) CArray object (newTask) as parameter

// Read/write access 1 (by reference)
void f1(TaskArray& tasks)
{
}
 
// Read/write access 2 (by pointer - my preferred way)
void f2(TaskArray* pTasks)
{
   ASSERT(pTasks);
}
 
// Read-only access
void f3(const TaskArray& tasks)
{
}

rishabhs wrote:
2)pointer to CArray object (&newTask)

TaskArray tasks;
 
f1(tasks);   // read/write access (by reference)
f2(&tasks);  // read/write access (by pointer -- easier to spot)
f3(tasks);   // read-only access (by const reference, which looks just like f1).


Regards,
Alvaro


All you need in this life is ignorance and confidence, and then success is sure. -- Mark Twain
GeneralRe: passing CArray in functions Pin
r i s h a b h s29-Jan-03 17:29
r i s h a b h s29-Jan-03 17:29 
Generalmy cancel button is not working Pin
Mr Bose Dayala29-Jan-03 0:02
Mr Bose Dayala29-Jan-03 0:02 
GeneralRe: my cancel button is not working Pin
Debs29-Jan-03 1:48
Debs29-Jan-03 1:48 
GeneralRe: my cancel button is not working Pin
Mr Bose Dayala29-Jan-03 2:13
Mr Bose Dayala29-Jan-03 2:13 
GeneralRe: my cancel button is not working Pin
Debs29-Jan-03 2:36
Debs29-Jan-03 2:36 
GeneralRe: my cancel button is not working Pin
Mr Bose Dayala29-Jan-03 2:40
Mr Bose Dayala29-Jan-03 2:40 
GeneralRe: my cancel button is not working Pin
Debs29-Jan-03 22:56
Debs29-Jan-03 22:56 
GeneralRe: my cancel button is not working Pin
Mr Bose Dayala29-Jan-03 23:05
Mr Bose Dayala29-Jan-03 23:05 
GeneralRe: my cancel button is not working Pin
Debs30-Jan-03 1:02
Debs30-Jan-03 1:02 
GeneralRe: my cancel button is not working Pin
Mr Bose Dayala30-Jan-03 1:23
Mr Bose Dayala30-Jan-03 1:23 
GeneralStrange that CFont::GetLogFont not const Pin
Moak28-Jan-03 23:14
Moak28-Jan-03 23:14 
GeneralRe: Strange that CFont::GetLogFont not const Pin
Member 568844324-Jan-13 6:21
Member 568844324-Jan-13 6:21 
GeneralSuperscipt in sourcecode/dialog caption Pin
John Oliver28-Jan-03 22:49
John Oliver28-Jan-03 22:49 
GeneralRe: Superscipt in sourcecode/dialog caption Pin
Joaquín M López Muñoz29-Jan-03 0:22
Joaquín M López Muñoz29-Jan-03 0:22 
GeneralRe: Superscipt in sourcecode/dialog caption Pin
John Oliver29-Jan-03 1:16
John Oliver29-Jan-03 1:16 
GeneralRe: Superscipt in sourcecode/dialog caption Pin
Joel Lucsy29-Jan-03 2:44
Joel Lucsy29-Jan-03 2:44 
GeneralRe: Superscipt in sourcecode/dialog caption Pin
John Oliver29-Jan-03 2:54
John Oliver29-Jan-03 2:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.