Click here to Skip to main content
15,886,362 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
GeneralRe: Operator [] Overloading Pin
Mikey_H26-May-09 0:36
Mikey_H26-May-09 0:36 
QuestionDoes anyone know about "MSUIM.Msg.Private"? Pin
fitatc25-May-09 22:00
fitatc25-May-09 22:00 
QuestionVC++ 6.0 + Processor Pack + Service Pack 5 cause stack overflow ? Pin
felixfan81925-May-09 21:57
felixfan81925-May-09 21:57 
QuestionHow to handle time delays Pin
V K 225-May-09 20:32
V K 225-May-09 20:32 
AnswerRe: How to handle time delays Pin
CPallini25-May-09 20:45
mveCPallini25-May-09 20:45 
AnswerRe: How to handle time delays Pin
Rajesh R Subramanian25-May-09 20:53
professionalRajesh R Subramanian25-May-09 20:53 
GeneralRe: How to handle time delays Pin
V K 225-May-09 20:54
V K 225-May-09 20:54 
GeneralRe: How to handle time delays Pin
CPallini25-May-09 20:59
mveCPallini25-May-09 20:59 
QuestionHelp on dynamic memory allocation and deallocation Pin
pani6825-May-09 20:08
pani6825-May-09 20:08 
AnswerRe: Help on dynamic memory allocation and deallocation Pin
«_Superman_»25-May-09 20:22
professional«_Superman_»25-May-09 20:22 
AnswerRe: Help on dynamic memory allocation and deallocation Pin
Cedric Moonen25-May-09 20:29
Cedric Moonen25-May-09 20:29 
AnswerRe: Help on dynamic memory allocation and deallocation Pin
Stuart Dootson25-May-09 23:08
professionalStuart Dootson25-May-09 23:08 
AnswerRe: Help on dynamic memory allocation and deallocation Pin
pani6826-May-09 2:15
pani6826-May-09 2:15 
QuestionHow do I convert .CPL to .MSC? Pin
Member 466633025-May-09 19:58
Member 466633025-May-09 19:58 
AnswerRe: How do I convert .CPL to .MSC? Pin
Stuart Dootson25-May-09 23:16
professionalStuart Dootson25-May-09 23:16 

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.