Hi,
I read the book C++ Primer, Fourth Edition By Stanley B. Lippman,
Jos¨¦e Lajoie, Barbara E. Moo
"If we define a class using the class keyword, then any members
defined before the first access label are implicitly private; ifwe
usethe struct keyword, then those members are public. Whether we define
a class using the class keyword or the struct keyword affects only the
default initial access level."
Now I defined a struct with overload operators == and != :
....
typedef struct RecordTwoSegmen tNo
{
int firstsegmentno;
int secondsegmentno ;
bool operator == (const RTSN& rmyrtsn);
bool operator != (const RTSN& rmyrtsn);
}RTSN;
bool RecordTwoSegmen tNo::operator ==(const RTSN &rmyrtsn)
{
return (firstsegmentno ==rmyrtsn.first segmentno &&
secondsegmentno ==rmyrtsn.secon dsegmentno);
}
bool RecordTwoSegmen tNo::operator !=(const RTSN &rmyrtsn)
{
return !(*this==rmyrts n);
}
....
The compiler (vs2005+winxp) report:
------ Build started: Project: maxborder, Configuration: Debug Win32 ------
Compiling...
maxborder.cpp
c:\maxborder\my point.h(16) : error C4430: missing type specifier - int
assumed. Note: C++ does not support default-int
c:\maxborder\my point.h(16) : error C2143: syntax error : missing ','
before '&'
c:\maxborder\my point.h(17) : error C4430: missing type specifier - int
assumed. Note: C++ does not support default-int
c:\maxborder\my point.h(17) : error C2143: syntax error : missing ','
before '&'
c:\maxborder\my point.h(21) : error C2511: 'bool
RecordTwoSegmen tNo::operator ==(const RTSN &)' : overloaded member
function not found in 'RecordTwoSegme ntNo'
c:\maxborder\my point.h(13) : see declaration of 'RecordTwoSegme ntNo'
c:\maxborder\my point.h(27) : error C2511: 'bool
RecordTwoSegmen tNo::operator !=(const RTSN &)' : overloaded member
function not found in 'RecordTwoSegme ntNo'
c:\maxborder\my point.h(13) : see declaration of
'RecordTwoSegme ntNo'
....
What is wrong? Is struct and class has another difference?
Thank you.
--
Thank you very much! :)
Thank this newsgroup very much! :)
Visual Studio 2005 Professional Edition
Windows XP Professional
I read the book C++ Primer, Fourth Edition By Stanley B. Lippman,
Jos¨¦e Lajoie, Barbara E. Moo
"If we define a class using the class keyword, then any members
defined before the first access label are implicitly private; ifwe
usethe struct keyword, then those members are public. Whether we define
a class using the class keyword or the struct keyword affects only the
default initial access level."
Now I defined a struct with overload operators == and != :
....
typedef struct RecordTwoSegmen tNo
{
int firstsegmentno;
int secondsegmentno ;
bool operator == (const RTSN& rmyrtsn);
bool operator != (const RTSN& rmyrtsn);
}RTSN;
bool RecordTwoSegmen tNo::operator ==(const RTSN &rmyrtsn)
{
return (firstsegmentno ==rmyrtsn.first segmentno &&
secondsegmentno ==rmyrtsn.secon dsegmentno);
}
bool RecordTwoSegmen tNo::operator !=(const RTSN &rmyrtsn)
{
return !(*this==rmyrts n);
}
....
The compiler (vs2005+winxp) report:
------ Build started: Project: maxborder, Configuration: Debug Win32 ------
Compiling...
maxborder.cpp
c:\maxborder\my point.h(16) : error C4430: missing type specifier - int
assumed. Note: C++ does not support default-int
c:\maxborder\my point.h(16) : error C2143: syntax error : missing ','
before '&'
c:\maxborder\my point.h(17) : error C4430: missing type specifier - int
assumed. Note: C++ does not support default-int
c:\maxborder\my point.h(17) : error C2143: syntax error : missing ','
before '&'
c:\maxborder\my point.h(21) : error C2511: 'bool
RecordTwoSegmen tNo::operator ==(const RTSN &)' : overloaded member
function not found in 'RecordTwoSegme ntNo'
c:\maxborder\my point.h(13) : see declaration of 'RecordTwoSegme ntNo'
c:\maxborder\my point.h(27) : error C2511: 'bool
RecordTwoSegmen tNo::operator !=(const RTSN &)' : overloaded member
function not found in 'RecordTwoSegme ntNo'
c:\maxborder\my point.h(13) : see declaration of
'RecordTwoSegme ntNo'
....
What is wrong? Is struct and class has another difference?
Thank you.
--
Thank you very much! :)
Thank this newsgroup very much! :)
Visual Studio 2005 Professional Edition
Windows XP Professional
Comment