Click here to Skip to main content
15,922,574 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: convert TCHAR to CString Pin
ThatsAlok26-May-09 22:19
ThatsAlok26-May-09 22:19 
GeneralRe: convert TCHAR to CString Pin
CPallini26-May-09 22:31
mveCPallini26-May-09 22:31 
GeneralRe: convert TCHAR to CString Pin
ThatsAlok28-May-09 6:01
ThatsAlok28-May-09 6:01 
GeneralRe: convert TCHAR to CString Pin
CPallini28-May-09 9:20
mveCPallini28-May-09 9:20 
GeneralRe: convert TCHAR to CString Pin
aravind.sn19-Jun-09 1:23
aravind.sn19-Jun-09 1:23 
QuestionPlease help me regarding :LoadCursorFromFile with .ani file Pin
ptr_Electron25-May-09 23:21
ptr_Electron25-May-09 23:21 
AnswerRe: Please help me regarding :LoadCursorFromFile with .ani file Pin
Stuart Dootson25-May-09 23:42
professionalStuart Dootson25-May-09 23:42 
GeneralRe: Please help me regarding :LoadCursorFromFile with .ani file Pin
ptr_Electron26-May-09 0:00
ptr_Electron26-May-09 0:00 
GeneralRe: Please help me regarding :LoadCursorFromFile with .ani file Pin
ptr_Electron26-May-09 0:17
ptr_Electron26-May-09 0:17 
GeneralRe: Some onePlease help me regarding :LoadCursorFromFile with .ani file Pin
ptr_Electron26-May-09 0:51
ptr_Electron26-May-09 0:51 
GeneralRe: Please help me regarding :LoadCursorFromFile with .ani file Pin
Stuart Dootson26-May-09 0:51
professionalStuart Dootson26-May-09 0:51 
GeneralRe: Please help me regarding :LoadCursorFromFile with .ani file Pin
ptr_Electron26-May-09 1:09
ptr_Electron26-May-09 1:09 
GeneralRe: Please help me regarding :LoadCursorFromFile with .ani file Pin
Stuart Dootson26-May-09 2:24
professionalStuart Dootson26-May-09 2:24 
GeneralRe: Please help me regarding :LoadCursorFromFile with .ani file Pin
ptr_Electron26-May-09 2:26
ptr_Electron26-May-09 2:26 
GeneralRe: Please help me regarding :LoadCursorFromFile with .ani file Pin
ptr_Electron26-May-09 21:46
ptr_Electron26-May-09 21:46 
GeneralRe: Please help me regarding :LoadCursorFromFile with .ani file Pin
Stuart Dootson26-May-09 21:49
professionalStuart Dootson26-May-09 21:49 
QuestionRe: Please help me regarding :LoadCursorFromFile with .ani file Pin
David Crow26-May-09 3:09
David Crow26-May-09 3:09 
QuestionOperator [] Overloading Pin
Mikey_H25-May-09 22:19
Mikey_H25-May-09 22:19 
AnswerRe: Operator [] Overloading Pin
CPallini25-May-09 22:43
mveCPallini25-May-09 22:43 
GeneralRe: Operator [] Overloading Pin
Mikey_H25-May-09 23:19
Mikey_H25-May-09 23:19 
AnswerRe: Operator [] Overloading Pin
Stuart Dootson25-May-09 22:49
professionalStuart Dootson25-May-09 22:49 
GeneralRe: Operator [] Overloading [modified] Pin
Mikey_H25-May-09 23:17
Mikey_H25-May-09 23:17 
GeneralRe: Operator [] Overloading Pin
Stuart Dootson25-May-09 23:35
professionalStuart Dootson25-May-09 23:35 
Mikey_H wrote:
(Is this only for user defined types? A pointer to a standard C array does not have to be derferenced does it?)


Quite right - pointers are special cases Smile | :)

Think about it - you're applying an operator defined on a class. The operator syntax a[b] is equivalent to a.operator[](b). So, with a pointer to the object, you can see that the method call syntax would be pa->operator[](b), or (*pa).operator[](b).

Mikey_H wrote:
That first issue is solved with the corrections, another small one exists tho, probably a similar issue.



(*array)[x][str] = y;



will give the error....

error C2440: 'return' : cannot convert from 'int' to 'AssocArray<ttype> &'

Do I need to dereference the AssocArray somehow too?


Here's some sample code I wrote that has the operator[] layout you want:

#include <string>
#include <iostream>

template<class Element>
class Array
{
public:
   Element& operator[](int index) { return e; }
private:
   Element e;
};

template<class Element>
class AssocArray
{
public:
   Element& operator[](std::string const& s) { return e; }
private:
   Element e;
};

int main()
{
   Array< std::string > as;
   AssocArray< std::string > aas;
   Array< AssocArray< std::string > > aaas;
   
   as[2];
   aas["Hello"];
   
   aaas[2]["Hello"] = "Test";
   std::cout << aaas[2]["Hello"] << std::endl;
}


Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

GeneralRe: Operator [] Overloading Pin
Mikey_H26-May-09 0:35
Mikey_H26-May-09 0:35 
AnswerRe: Operator [] Overloading Pin
Cedric Moonen25-May-09 23:31
Cedric Moonen25-May-09 23:31 

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.