Click here to Skip to main content
16,005,120 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: popup menu Pin
deeps_cute5-Apr-07 1:00
deeps_cute5-Apr-07 1:00 
GeneralRe: popup menu Pin
Naveen5-Apr-07 1:12
Naveen5-Apr-07 1:12 
QuestionDynamically Extending Arrays? Pin
chown4-Apr-07 17:18
chown4-Apr-07 17:18 
AnswerRe: Dynamically Extending Arrays? Pin
GameProfessor4-Apr-07 17:25
GameProfessor4-Apr-07 17:25 
AnswerRe: Dynamically Extending Arrays? Pin
William.Wang4-Apr-07 22:59
William.Wang4-Apr-07 22:59 
QuestionHow to create indefinite number of UI-thread with MFC Pin
GameProfessor4-Apr-07 16:41
GameProfessor4-Apr-07 16:41 
AnswerRe: How to create indefinite number of UI-thread with MFC Pin
Naveen4-Apr-07 17:24
Naveen4-Apr-07 17:24 
QuestionTrying to get my LinkedList class to compile... Pin
Pat Munns4-Apr-07 15:54
Pat Munns4-Apr-07 15:54 
The code won't compile, but I only get some silly messages that don't help. I must be doing something illegal, but I don't have the knowledge of C++ to know what. Does anything catch anyone's eye? This is a basic linked list class that I'm trying to add enumerator functionality to. Project is set to plain unmanaged C++. Thanks in advance...

#pragma once
#include <assert.h>

template <class T>
class LinkedList
{
public:
class Enumerator
{
friend Enumerator LinkedList<T>::GetEnumerator();
public:
virtual T GetCurrent()
{
return _current->Item;
}

virtual bool MoveNext()
{
if (_current == 0)
_current = _linkedList->_head;
else
_current = _current->Next;

return _current != 0;
}

virtual void Reset()
{
_current = 0;
}

protected:
LinkedList<T> *_linkedList;
ListNode *_current;

Enumerator() : _current(0)
{
}

};

LinkedList() : _count(0), _head(0)
{
}

LinkedList(const LinkedList<T> &objectToCopy) : _count(objectToCopy._count)
{
if (objectToCopy._head == 0)
_head = 0;
else
{
_head = new ListNode;
_head->Item = objectToCopy._head->Item;

ListNode *newestNode = _head;
for (ListNode *nodeToCopy = objectToCopy._head->Next; nodeToCopy != 0; nodeToCopy = nodeToCopy->Next)
{
newestNode->Next = new ListNode;
newestNode = newestNode->Next;
newestNode->Item = nodeToCopy->Item;
}

newestNode->Next = 0;
}
}

virtual ~LinkedList()
{
while (_count > 0)
RemoveAt(0);
}

virtual T GetItem(int index)
{
return (AddressOf(index))->Item;
}

virtual int GetCount()
{
return _count;
}

virtual void Add(T value)
{
Insert(_count, value);
}

virtual void Insert(int index, T value)
{
assert(index >= 0 && index <= _count);

ListNode *nodeToInsert = new ListNode;
nodeToInsert->Item = value;
nodeToInsert->Next = AddressOf(index);
if (index == 0)
_head = nodeToInsert;
else
(AddressOf(index - 1))->Next = nodeToInsert;

_count++;
}

virtual void RemoveAt(int index)
{
assert(index >= 0 && index <= _count - 1);

ListNode *nodeToRemove = AddressOf(index);
if (index == 0)
_head = _head->Next;
else
(AddressOf(index - 1))->Next = (AddressOf(index + 1));

_count--;

delete nodeToRemove;
}

virtual Enumerator GetEnumerator()
{
Enumerator newEnumerator;
newEnumerator._linkedList = this;
return newEnumerator;
}

protected:
struct ListNode
{
T Item;
ListNode *Next;
};

int _count;
ListNode *_head;

virtual ListNode *AddressOf(int index)
{
if (index < 0 || index > _count - 1)
return 0;
else
{
ListNode *node = _head;

for (int i = 0; i < index; i++)
node = node->Next;

return node;
}
}

};


AnswerRe: Trying to get my LinkedList class to compile... Pin
John R. Shaw4-Apr-07 19:15
John R. Shaw4-Apr-07 19:15 
GeneralRe: Trying to get my LinkedList class to compile... Pin
Pat Munns4-Apr-07 20:45
Pat Munns4-Apr-07 20:45 
AnswerRe: Trying to get my LinkedList class to compile... Pin
Pat Munns5-Apr-07 6:19
Pat Munns5-Apr-07 6:19 
GeneralRe: Trying to get my LinkedList class to compile... Pin
John R. Shaw6-Apr-07 1:51
John R. Shaw6-Apr-07 1:51 
QuestionFast "reboot" or re-loading the registry without reboot Pin
sjm964-Apr-07 15:51
sjm964-Apr-07 15:51 
QuestionCMultiDocTemplate - how to move a document to the top [modified] Pin
chienlim4-Apr-07 13:45
chienlim4-Apr-07 13:45 
Questiondisplay grayscale image in visual c++ 6.0 Pin
gurucplusplus4-Apr-07 10:34
gurucplusplus4-Apr-07 10:34 
AnswerRe: display grayscale image in visual c++ 6.0 Pin
lafleon4-Apr-07 13:32
lafleon4-Apr-07 13:32 
GeneralRe: display grayscale image in visual c++ 6.0 Pin
gurucplusplus4-Apr-07 19:47
gurucplusplus4-Apr-07 19:47 
GeneralRe: display grayscale image in visual c++ 6.0 Pin
cp98764-Apr-07 20:34
cp98764-Apr-07 20:34 
AnswerRe: display grayscale image in visual c++ 6.0 Pin
Hamid_RT5-Apr-07 18:50
Hamid_RT5-Apr-07 18:50 
QuestionScanning the IEEE or GPIB buss Pin
pblais4-Apr-07 10:14
pblais4-Apr-07 10:14 
AnswerRe: Scanning the IEEE or GPIB buss Pin
lafleon4-Apr-07 10:25
lafleon4-Apr-07 10:25 
GeneralRe: Scanning the IEEE or GPIB buss Pin
pblais5-Apr-07 2:38
pblais5-Apr-07 2:38 
QuestionDisplaying file sizes larger than 2GB? [modified] Pin
Wes Jones4-Apr-07 7:43
Wes Jones4-Apr-07 7:43 
AnswerRe: Displaying file sizes larger than 2GB? Pin
Mark Salsbery4-Apr-07 7:54
Mark Salsbery4-Apr-07 7:54 
GeneralRe: Displaying file sizes larger than 2GB? Pin
Wes Jones4-Apr-07 8:23
Wes Jones4-Apr-07 8:23 

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.