Click here to Skip to main content
15,921,840 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: LPTSTR to char* Pin
led mike17-Aug-06 6:55
led mike17-Aug-06 6:55 
QuestionRe: LPTSTR to char* Pin
David Crow17-Aug-06 6:55
David Crow17-Aug-06 6:55 
AnswerRe: LPTSTR to char* Pin
Zac Howland17-Aug-06 6:57
Zac Howland17-Aug-06 6:57 
Questionc++ Pin
jon-8017-Aug-06 6:05
professionaljon-8017-Aug-06 6:05 
AnswerRe: c++ Pin
Zac Howland17-Aug-06 6:13
Zac Howland17-Aug-06 6:13 
GeneralRe: c++ Pin
jon-8017-Aug-06 8:02
professionaljon-8017-Aug-06 8:02 
GeneralRe: c++ Pin
Zac Howland17-Aug-06 8:16
Zac Howland17-Aug-06 8:16 
GeneralRe: c++ Pin
jon-8018-Aug-06 9:01
professionaljon-8018-Aug-06 9:01 
The weird thing is that I'm getting access related errors when I'm trying to clean-up from the calling class.

...
CSentenceList::~CSentenceList()
{
// Clear the data
CGenericNode<char*> *pTemp = Sentences.m_pFirst;
while(pTemp != NULL)
{
CGenericNode<char*> *pRemember = pTemp->m_pNextNode;
free (pTemp->data);
pTemp = pRemember;
}
}

...

c:\Documents and Settings\Jon\My Documents\Visual Studio Projects\IAD Practice and Assignment\C++ - Assignment\02 & 03 - Sentence\SentenceClass\SentenceList.cpp(19): error C2248: 'CGenericList<T>::m_pFirst' : cannot access private member declared in class 'CGenericList<T>'
with
[
T=char *
]
and
[
T=char *
]

c:\Documents and Settings\Jon\My Documents\Visual Studio Projects\IAD Practice and Assignment\C++ - Assignment\02 & 03 - Sentence\SentenceClass\SentenceList.cpp(22): error C2248: 'CGenericNode<T>::m_pNextNode' : cannot access private member declared in class 'CGenericNode<T>'
with
[
T=char *
]
and
[
T=char *
]



CGenericList.h
#pragma once
#include ".\GenericNode.h"
#include <iostream>
#include <stdlib.h>
#include <tchar.h>
using namespace std;

template<class T>
class CGenericList
{
public:
CGenericList(void)
{
m_pFirst = NULL;
m_pLast = NULL;
m_iCount = 0;
}

virtual ~CGenericList(void)
{
Clear();
}

void Insert(T pData)
{
// create the node to store our data
CGenericNode<T> *pNode = new CGenericNode<T>;
pNode->data = pData; // set the payload

if(m_iCount == 0)
{
m_pFirst = pNode;
m_pLast = pNode;
}
else
{
m_pLast->m_pNextNode = pNode;
m_pLast = pNode;
}

m_iCount++;
}

bool Find(T pData)
{
CGenericNode<T> *pTemp = m_pFirst;
while(pTemp != NULL)
{
if(pTemp->data == pData)
return true;
pTemp = pTemp->m_pNextNode;
}

return false;
}

bool Remove(T pData)
{
CGenericNode<T> *pTemp = m_pFirst;
CGenericNode<T> *pPrevious = NULL; // keep track of previous node

while(pTemp != NULL)
{
if(pTemp->data == pData)
{
// we found the node!
RemoveNode(pPrevious, pTemp); // call helper method
return true; // true indicates that something was removed
}

pPrevious = pTemp; // remember the previous node
pTemp = pTemp->m_pNextNode;
}

return false; // we found nothing here
}

int GetCount()
{
return m_iCount;
}

void Display()
{
CGenericNode<T> *pTemp = m_pFirst;
int iCount = 0;
while(pTemp != NULL)
{
iCount++;
cout << iCount << "|";
cout << pTemp->data << _T(" ");
cout << endl;
pTemp = pTemp->m_pNextNode;
}
}
protected:
int m_iCount;
CGenericNode<T> *m_pFirst;
CGenericNode<T> *m_pLast;

// helper method

void Clear() // empties the list
{

CGenericNode<T> *pTemp = m_pFirst;
// clear the nodes
while(pTemp != NULL)
{
CGenericNode<T> *pRemember = pTemp->m_pNextNode;
delete pTemp;
pTemp = pRemember;
}

m_iCount = 0;
}

void RemoveNode(CGenericNode<T> *pPrevious, CGenericNode<T> *pTemp)
{
if(pPrevious == NULL) // remove the first node
{
m_pFirst = pTemp->m_pNextNode;
if(m_pFirst == NULL) m_pLast = NULL; // this was the only node
delete pTemp; // delete the original node
}
else
{
pPrevious->m_pNextNode = pTemp->m_pNextNode; // skip this node
if(pPrevious->m_pNextNode == NULL) // in case we are deleting the last node
m_pLast = pPrevious;
delete pTemp;
}

m_iCount--;
}

};

CGenericNode.h
#pragma once
#include <stdlib.h>

// forward declaration of CGenericList (it is a template)
// and is a friend of CGenericNode
template<class T> class CGenericList;

// declaration of CGenericNode
template<class T>
class CGenericNode
{
friend CGenericList<T>;

public:
CGenericNode()
{
m_pNextNode = NULL;
}

T data;

//protected:
// T m_data;

private:
CGenericNode<T> *m_pNextNode;
};


Jon
QuestionLinking Error /outportb Pin
cahit2317-Aug-06 5:55
cahit2317-Aug-06 5:55 
AnswerRe: Linking Error /outportb Pin
kakan17-Aug-06 20:48
professionalkakan17-Aug-06 20:48 
Questionproblems with winsock Pin
afpr17-Aug-06 5:43
afpr17-Aug-06 5:43 
AnswerRe: problems with winsock Pin
lucy17-Aug-06 5:47
lucy17-Aug-06 5:47 
GeneralRe: problems with winsock [modified] Pin
afpr17-Aug-06 6:04
afpr17-Aug-06 6:04 
GeneralRe: problems with winsock Pin
Zac Howland17-Aug-06 6:23
Zac Howland17-Aug-06 6:23 
GeneralRe: problems with winsock [modified] Pin
afpr17-Aug-06 6:26
afpr17-Aug-06 6:26 
GeneralRe: problems with winsock Pin
Zac Howland17-Aug-06 6:58
Zac Howland17-Aug-06 6:58 
GeneralRe: problems with winsock Pin
afpr17-Aug-06 8:16
afpr17-Aug-06 8:16 
GeneralRe: problems with winsock Pin
David Crow17-Aug-06 8:24
David Crow17-Aug-06 8:24 
GeneralRe: problems with winsock Pin
Zac Howland17-Aug-06 9:50
Zac Howland17-Aug-06 9:50 
GeneralRe: problems with winsock Pin
afpr17-Aug-06 10:33
afpr17-Aug-06 10:33 
GeneralRe: problems with winsock Pin
Zac Howland17-Aug-06 10:42
Zac Howland17-Aug-06 10:42 
GeneralRe: problems with winsock Pin
afpr17-Aug-06 11:40
afpr17-Aug-06 11:40 
GeneralRe: problems with winsock Pin
Hamid_RT18-Aug-06 6:31
Hamid_RT18-Aug-06 6:31 
QuestionselectSingleNode() and setProperty() Pin
harilal17-Aug-06 5:32
harilal17-Aug-06 5:32 
Questionunit test Pin
lucy17-Aug-06 5:18
lucy17-Aug-06 5:18 

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.