Click here to Skip to main content
15,912,756 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionTemplates and protected members [modified] Pin
JKallen20-Aug-06 7:46
JKallen20-Aug-06 7:46 
AnswerRe: Templates and protected members Pin
Justin Tay20-Aug-06 8:14
Justin Tay20-Aug-06 8:14 
GeneralRe: Templates and protected members Pin
JKallen20-Aug-06 8:32
JKallen20-Aug-06 8:32 
GeneralRe: Templates and protected members [modified] Pin
Justin Tay20-Aug-06 8:41
Justin Tay20-Aug-06 8:41 
GeneralRe: Templates and protected members [modified] Pin
JKallen20-Aug-06 9:11
JKallen20-Aug-06 9:11 
GeneralRe: Templates and protected members Pin
jk chan21-Aug-06 18:06
jk chan21-Aug-06 18:06 
AnswerRe: Templates and protected members Pin
Michael Dunn20-Aug-06 10:46
sitebuilderMichael Dunn20-Aug-06 10:46 
Questionios::nocreate and acces modifiers (2) Pin
jon-8020-Aug-06 7:32
professionaljon-8020-Aug-06 7:32 
I was getting these errors when trying to use ios::nocreate in order to check whether a file exists prior to opening it:

void CSentenceList::readFile(char strFileToRead[MAX_FILENAME_LENGTH])
{
char strLine[MAX_SENTENCE_LENGTH + 1];

ofstream fileToRead(strFileToRead,ios::nocreate); // ios::nocreate does not seem to exist

while (!fileToRead.eof() && Size < MAX_LINES)
// Read line of text from file and update Sentences.strSentence.
{ fileToRead.getline(strLine, MAX_SENTENCE_LENGTH);
Sentences.Insert(strdup(strLine));
Size++;
}
fileToRead.close();

Error
SentenceList.cpp(23): error C2039: 'nocreate' : is not a member of 'std::basic_ios<_Elem,_Traits>'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]

SentenceList.cpp(23): error C2065: 'nocreate' : undeclared identifier

SentenceList.cpp(27): error C2039: 'getline' : is not a member of 'std::basic_ofstream<_Elem,_Traits>'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]

I assume that VS2003 has other functions to check whether the file exists, since these are basic C/C+ constructs.

Similarly I never reckoned why I had problems with using protected members of class templates:

SentenceList.h
class CSentenceList : public CGenericList<char*>


SentenceList.cpp
CSentenceList::~CSentenceList()
{Sentences.m_pFirst->data = NULL;} // this statement is incorrect but illustrates the point

Error
…SentenceList.cpp(16): error C2248: 'CGenericList<T>::m_pFirst' : cannot access protected member declared in class 'CGenericList<T>'
with
[
T=char *
]
and
[
T=char *
]

…\SentenceClass\SentenceList.cpp(16): error C2248: 'CGenericNode<T>::data' : cannot access protected member declared in class 'CGenericNode<T>'
with
[
T=char *
]
and
[
T=char *
]

GenericList.h
class CGenericList
...
protected:
int m_iCount;
CGenericNode<T> *m_pFirst;
CGenericNode<T> *m_pLast;
...

GenericNode.h
class CGenericNode
...
protected:
T data;
...



Jon
AnswerRe: ios::nocreate and acces modifiers (2) [modified] Pin
Waldermort20-Aug-06 7:58
Waldermort20-Aug-06 7:58 
Questionios::nocreate Pin
jon-8020-Aug-06 7:01
professionaljon-8020-Aug-06 7:01 
AnswerRe: ios::nocreate Pin
Bob X20-Aug-06 10:00
Bob X20-Aug-06 10:00 
AnswerRe: ios::nocreate Pin
jon-8020-Aug-06 10:18
professionaljon-8020-Aug-06 10:18 
GeneralRe: ios::nocreate [modified] Pin
Bob X20-Aug-06 16:48
Bob X20-Aug-06 16:48 
Questionomanip... was this class superseded in vs2003? Pin
jon-8020-Aug-06 6:54
professionaljon-8020-Aug-06 6:54 
AnswerRe: omanip... was this class superseded in vs2003? Pin
Christian Graus20-Aug-06 11:16
protectorChristian Graus20-Aug-06 11:16 
GeneralRe: omanip... was this class superseded in vs2003? Pin
jon-8021-Aug-06 5:05
professionaljon-8021-Aug-06 5:05 
Questionhow to control windows explorer ? Pin
Kriptoz20-Aug-06 6:42
Kriptoz20-Aug-06 6:42 
AnswerRe: how to control windows explorer ? Pin
Waldermort20-Aug-06 7:28
Waldermort20-Aug-06 7:28 
Questionhow to get the following info. from a thread Pin
zhijia.yuan20-Aug-06 6:38
zhijia.yuan20-Aug-06 6:38 
AnswerRe: how to get the following info. from a thread Pin
Michael Dunn20-Aug-06 6:51
sitebuilderMichael Dunn20-Aug-06 6:51 
AnswerRe: how to get the following info. from a thread Pin
Hamid_RT22-Aug-06 7:27
Hamid_RT22-Aug-06 7:27 
Questionstack around the variable 'values' was corrupted Pin
jon-8020-Aug-06 6:01
professionaljon-8020-Aug-06 6:01 
AnswerRe: stack around the variable 'values' was corrupted Pin
Michael Dunn20-Aug-06 6:06
sitebuilderMichael Dunn20-Aug-06 6:06 
GeneralRe: stack around the variable 'values' was corrupted Pin
jon-8020-Aug-06 10:22
professionaljon-8020-Aug-06 10:22 
GeneralRe: stack around the variable 'values' was corrupted Pin
Michael Dunn20-Aug-06 10:35
sitebuilderMichael Dunn20-Aug-06 10:35 

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.