Hi,
I am in trouble with some of my code. I try for a couple of days to implement an overloaded template method. But it doesn’t runs.
I try to integrate the overloaded template method “T &operator[] (int i)”, you can see it below.
template <class T>
class List
{
private:
class ListNode
{
public:
ListNode *previousNode;
ListNode *nextNode;
T content;
} *node;
ListNode *firstNode;
ListNode *lastNode;
int nodeCount;
public:
...
T &operator[] (int i)
{
return firstNode->content;
}
// <TR> WORKAROUNG: use operator overloading
T getContent(int Index)
{
ListNode *currentListNode = getListNodeAtIndex(Index);
return currentListNode->content;
}
};
#include <iostream>
#include "core.h"
#include <string>
using namespace std;
int main()
{
List<string> *lst = new List<string>();
....
for (int i = 295; i < 305; i++)
{
//lst->getContent(i) = "Test";
string test = lst;
}
system("PAUSE");
return 0;
}
If I use “T getContent(int Index)”, It runs. But If I use “T &operator[] (int i)”, IntelliSense says following: “2 IntelliSense: no suitable user-defined conversion from "List<std::string>" to "std::string" exists c:\development\meteo\application\Application.cpp 26 17 application”
I don’t know why he says this. Also I tried moving T &operator[] (int i)
Into the ListNode class, but this doesn’t runs, too.
I don’t know, if it is important for you, but I want to store this in a DLL File.
I hope everyone can help me. I am on the way to despair.
I hope you can understand me, my English is not the best.
Yours sincerely
Dennis Köhler aka Pixma