Re: [Dev-C++] Syntax problem??? Parser error??
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Alvin T. <al...@th...> - 2003-10-28 20:50:00
|
ah, i see!
-alvin
P.D. van Zelst wrote:
> It gets checked. The "this" pointer passed to const member functions is
> const as well, so any attempt to modify member variables (or call non-const
> member functions) will result in errors.
>
>
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf Of Alvin
> Thompson
> Sent: Tuesday, October 28, 2003 8:20 PM
> To: Per Westermark
> Cc: de...@li...; dev...@li...
> Subject: Re: [Dev-C++] Syntax problem??? Parser error??
>
> i didn't know that either. does the compiler actually check the code to
> see if it tries to modify the List (and generate a compile error if it
> does), or is it more like a "gentleman's agreement"?
>
> -alvin
>
>
> Per Westermark wrote:
>
>
>>you have a class
>>
>>class List {
>>public:
>> bool isEmpty();
>>};
>>
>>If you rewrite it to:
>>
>>class List {
>>public:
>> bool isEmpty() const;
>>};
>>
>>you tell the compiler that isEmpty() will not perform any changes of the
>>List object. This informs the compiler to allow isEmpty() calls for a
>>const list object such as:
>>
>>void my_function(const List& list) {
>> if (!list.isEmpty()) {
>> ....
>> }
>>}
>>
>>/Per W
>>
>>On Tue, 28 Oct 2003, Devan Lippman wrote:
>>
>>
>>
>>>>From the following line of code:
>>> bool empty = aList.isEmpty();
>>>I'm getting this error:
>>> passing `const List' as `this' argument of `bool
>>> List::isEmpty()' discards qualifiers
>>>
>>>isEmpty() is a member function that returns a bool
>>>
>>>Thank you,
>>>Devan Lippman <dli...@co...>
>>>(617) 571-3017
>>>
>>>Using Dev-C++ version: 4.9.8.4
>>>
>>>Compiler Log:
>>>Compiler: Default compiler
>>>Building Makefile: "C:\Dev-Cpp\HW6\Makefile.win"
>>>Executing make...
>>>make.exe -f "C:\Dev-Cpp\HW6\Makefile.win" all
>>>g++.exe -c dlippman-6.cpp -o dlippman-6.o -I"C:/Dev-Cpp/include/c++"
>
> -I"C:/Dev-
>
>>>Cpp/include/c++/mingw32" -I"C:/Dev-Cpp/include/c++/backward" -I"C:/Dev-
>>>Cpp/include"
>>>
>>>dlippman-6.cpp: In function `void firstElement(const List&, ListItemType&,
>>> bool&)':
>>>dlippman-6.cpp:54: passing `const List' as `this' argument of `bool
>>>
>>> List::isEmpty()' discards qualifiers
>>>
>>>dlippman-6.cpp:56: passing `const List' as `this' argument of `void
>>> List::retrieve(int, ListItemType&, bool&)' discards qualifiers
>>>
>>>dlippman-6.cpp: In function `void lastElement(const List&, ListItemType&,
>>> bool&)':
>>>dlippman-6.cpp:63: passing `const List' as `this' argument of `bool
>>> List::isEmpty()' discards qualifiers
>>>
>>>dlippman-6.cpp:63: passing `const List' as `this' argument of `int
>>> List::getLength()' discards qualifiers
>>>
>>>dlippman-6.cpp:63: passing `const List' as `this' argument of `void
>>> List::retrieve(int, ListItemType&, bool&)' discards qualifiers
>>>
>>>dlippman-6.cpp: In function `void lookupValue(const List&, int, int&,
>
> bool&)':
>
>>>dlippman-6.cpp:75: passing `const List' as `this' argument of `int
>>> List::getLength()' discards qualifiers
>>>
>>>dlippman-6.cpp:76: passing `const List' as `this' argument of `void
>>> List::retrieve(int, ListItemType&, bool&)' discards qualifiers
>>>
>>>dlippman-6.cpp: In function `void testList()':
>>>
>>>dlippman-6.cpp:142: parse error before `{' token
>>>
>>>dlippman-6.cpp:149: return-statement with a value, in function declared
>
> with a
>
>>> void return type
>>>
>>>dlippman-6.cpp:153: parse error at end of input
>>>
>>>make.exe: *** [dlippman-6.o] Error 1
>>>
>>>Execution terminated
>>>
>>>
>>>
>>
>>
>>
>>
>>-------------------------------------------------------
>>This SF.net email is sponsored by: SF.net Giveback Program.
>>Does SourceForge.net help you be more productive? Does it
>>help you create better code? SHARE THE LOVE, and help us help
>>YOU! Click Here: http://sourceforge.net/donate/
>>_______________________________________________
>>Dev-cpp-users mailing list
>>Dev...@li...
>>TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
>>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: SF.net Giveback Program.
> Does SourceForge.net help you be more productive? Does it
> help you create better code? SHARE THE LOVE, and help us help
> YOU! Click Here: http://sourceforge.net/donate/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: SF.net Giveback Program.
> Does SourceForge.net help you be more productive? Does it
> help you create better code? SHARE THE LOVE, and help us help
> YOU! Click Here: http://sourceforge.net/donate/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|