F
fcvcnet
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 RecordTwoSegmentNo
{
int firstsegmentno;
int secondsegmentno;
bool operator == (const RTSN& rmyrtsn);
bool operator != (const RTSN& rmyrtsn);
}RTSN;
bool RecordTwoSegmentNo:
perator ==(const RTSN &rmyrtsn)
{
return (firstsegmentno==rmyrtsn.firstsegmentno &&
secondsegmentno==rmyrtsn.secondsegmentno);
}
bool RecordTwoSegmentNo:
perator !=(const RTSN &rmyrtsn)
{
return !(*this==rmyrtsn);
}
....
The compiler (vs2005+winxp) report:
------ Build started: Project: maxborder, Configuration: Debug Win32 ------
Compiling...
maxborder.cpp
c:\maxborder\mypoint.h(16) : error C4430: missing type specifier - int
assumed. Note: C++ does not support default-int
c:\maxborder\mypoint.h(16) : error C2143: syntax error : missing ','
before '&'
c:\maxborder\mypoint.h(17) : error C4430: missing type specifier - int
assumed. Note: C++ does not support default-int
c:\maxborder\mypoint.h(17) : error C2143: syntax error : missing ','
before '&'
c:\maxborder\mypoint.h(21) : error C2511: 'bool
RecordTwoSegmentNo:
perator ==(const RTSN &)' : overloaded member
function not found in 'RecordTwoSegmentNo'
c:\maxborder\mypoint.h(13) : see declaration of 'RecordTwoSegmentNo'
c:\maxborder\mypoint.h(27) : error C2511: 'bool
RecordTwoSegmentNo:
perator !=(const RTSN &)' : overloaded member
function not found in 'RecordTwoSegmentNo'
c:\maxborder\mypoint.h(13) : see declaration of
'RecordTwoSegmentNo'
....
What is wrong? Is struct and class has another difference?
Thank you.
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 RecordTwoSegmentNo
{
int firstsegmentno;
int secondsegmentno;
bool operator == (const RTSN& rmyrtsn);
bool operator != (const RTSN& rmyrtsn);
}RTSN;
bool RecordTwoSegmentNo:
{
return (firstsegmentno==rmyrtsn.firstsegmentno &&
secondsegmentno==rmyrtsn.secondsegmentno);
}
bool RecordTwoSegmentNo:
{
return !(*this==rmyrtsn);
}
....
The compiler (vs2005+winxp) report:
------ Build started: Project: maxborder, Configuration: Debug Win32 ------
Compiling...
maxborder.cpp
c:\maxborder\mypoint.h(16) : error C4430: missing type specifier - int
assumed. Note: C++ does not support default-int
c:\maxborder\mypoint.h(16) : error C2143: syntax error : missing ','
before '&'
c:\maxborder\mypoint.h(17) : error C4430: missing type specifier - int
assumed. Note: C++ does not support default-int
c:\maxborder\mypoint.h(17) : error C2143: syntax error : missing ','
before '&'
c:\maxborder\mypoint.h(21) : error C2511: 'bool
RecordTwoSegmentNo:
function not found in 'RecordTwoSegmentNo'
c:\maxborder\mypoint.h(13) : see declaration of 'RecordTwoSegmentNo'
c:\maxborder\mypoint.h(27) : error C2511: 'bool
RecordTwoSegmentNo:
function not found in 'RecordTwoSegmentNo'
c:\maxborder\mypoint.h(13) : see declaration of
'RecordTwoSegmentNo'
....
What is wrong? Is struct and class has another difference?
Thank you.