Re: [Dev-C++] Syntax problem??? Parser error??
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2003-10-28 18:55:09
|
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
>
>
>
|