Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Is 'close' a reserved word in C++ ?

Reply
Thread Tools

Is 'close' a reserved word in C++ ?

 
 
Roman Werpachowski
Guest
Posts: n/a
 
      12-29-2005
The following code does not compile:

#include <iostream>

class close {
public:
void message();
};

inline void close::message()
{
std::cout << "Close class\n";
}

int main()
{
close c;

c.message();
}

The message given by g++ is:

other.cc: In function `int main()':
other.cc:15: error: `close' undeclared (first use this function)
other.cc:15: error: (Each undeclared identifier is reported only once for each
function it appears in.)
other.cc:15: error: syntax error before `;' token
other.cc:17: error: `c' undeclared (first use this function)

I don't understand it. I've looked for a list of reserved words in C++ and
'close' is not there.

--
Roman Werpachowski
/--------==============--------\
| http://www.cft.edu.pl/~roman |
\--------==============--------/
 
Reply With Quote
 
 
 
 
Thomas Tutone
Guest
Posts: n/a
 
      12-29-2005

Roman Werpachowski wrote:
> The following code does not compile:
>
> #include <iostream>
>
> class close {
> public:
> void message();
> };
>
> inline void close::message()
> {
> std::cout << "Close class\n";
> }
>
> int main()
> {
> close c;
>
> c.message();
> }
>
> The message given by g++ is:
>
> other.cc: In function `int main()':
> other.cc:15: error: `close' undeclared (first use this function)
> other.cc:15: error: (Each undeclared identifier is reported only once for each
> function it appears in.)
> other.cc:15: error: syntax error before `;' token
> other.cc:17: error: `c' undeclared (first use this function)
>
> I don't understand it. I've looked for a list of reserved words in C++ and
> 'close' is not there.


close is not a reserved word in C++. Comeau compiles your program
fine. What version of gcc are you using?

Best regards,

Tom

 
Reply With Quote
 
 
 
 
Roman Werpachowski
Guest
Posts: n/a
 
      12-29-2005
On the 28 Dec 2005 17:04:18 -0800, Thomas Tutone wrote:

>> I don't understand it. I've looked for a list of reserved words in C++ and
>> 'close' is not there.

>
> close is not a reserved word in C++. Comeau compiles your program
> fine. What version of gcc are you using?


3.3.6 compiled for x86_64


--
Roman Werpachowski
/--------==============--------\
| http://www.cft.edu.pl/~roman |
\--------==============--------/
 
Reply With Quote
 
Roman Werpachowski
Guest
Posts: n/a
 
      12-29-2005
On the Thu, 29 Dec 2005 01:08:16 +0000 (UTC), Roman Werpachowski wrote:
> On the 28 Dec 2005 17:04:18 -0800, Thomas Tutone wrote:
>
>>> I don't understand it. I've looked for a list of reserved words in C++ and
>>> 'close' is not there.

>>
>> close is not a reserved word in C++. Comeau compiles your program
>> fine. What version of gcc are you using?

>
> 3.3.6 compiled for x86_64


The darn thing compiles when I remove

#include <iostream>

line.

--
Roman Werpachowski
/--------==============--------\
| http://www.cft.edu.pl/~roman |
\--------==============--------/
 
Reply With Quote
 
Roman Werpachowski
Guest
Posts: n/a
 
      12-29-2005
On the Thu, 29 Dec 2005 01:11:17 +0000 (UTC), Roman Werpachowski wrote:
> On the Thu, 29 Dec 2005 01:08:16 +0000 (UTC), Roman Werpachowski wrote:
>> On the 28 Dec 2005 17:04:18 -0800, Thomas Tutone wrote:
>>
>>>> I don't understand it. I've looked for a list of reserved words in C++ and
>>>> 'close' is not there.
>>>
>>> close is not a reserved word in C++. Comeau compiles your program
>>> fine. What version of gcc are you using?

>>
>> 3.3.6 compiled for x86_64

>
> The darn thing compiles when I remove
>
> #include <iostream>
>
> line.


It seems there are close() methods defined in std:: namespace. But I did
*not* write:

using namespace std;

in the original source!


--
Roman Werpachowski
/--------==============--------\
| http://www.cft.edu.pl/~roman |
\--------==============--------/
 
Reply With Quote
 
puzzlecracker
Guest
Posts: n/a
 
      12-29-2005

> It seems there are close() methods defined in std:: namespace. But I did
> *not* write:
>
> using namespace std;
>


it doesn't make sense. There is a different reason -- likely a COMPILE
RELATED.

anyone knows the exact rules for look up?

 
Reply With Quote
 
Dietmar Kuehl
Guest
Posts: n/a
 
      12-29-2005
Roman Werpachowski wrote:
> I don't understand it. I've looked for a list of reserved words in C++ and
> 'close' is not there.


The problem is almost certainly the declaration of POSIX' 'close()'
function. This is declared via implicit inclusion of <unistd.h> from
<iostream>. Although I would guess that most if not all implementations
on POSIX systems include this header, I would consider it to be a bug
in the implementation. However, conflicting with names of system
functions in global scope is probably best avoided.
--
<(E-Mail Removed)> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
 
Reply With Quote
 
Jonathan Mcdougall
Guest
Posts: n/a
 
      12-29-2005
Roman Werpachowski wrote:
> The following code does not compile:
>
> #include <iostream>
>
> class close {
> public:
> void message();
> };
>
> inline void close::message()
> {
> std::cout << "Close class\n";
> }
>
> int main()
> {
> close c;
>
> c.message();
> }
>
> The message given by g++ is:
>
> other.cc: In function `int main()':
> other.cc:15: error: `close' undeclared (first use this function)
> other.cc:15: error: (Each undeclared identifier is reported only once for each
> function it appears in.)
> other.cc:15: error: syntax error before `;' token
> other.cc:17: error: `c' undeclared (first use this function)
>
> I don't understand it. I've looked for a list of reserved words in C++ and
> 'close' is not there.


You mean if you actually copy/paste what's written in your message you
get these errors? This seems highly unlikely to me.


Jonathan

 
Reply With Quote
 
Roman Werpachowski
Guest
Posts: n/a
 
      12-29-2005
On the 28 Dec 2005 18:12:30 -0800, Jonathan Mcdougall wrote:

> You mean if you actually copy/paste what's written in your message you
> get these errors?


Yup.

> This seems highly unlikely to me.


So now there is two of us.


--
Roman Werpachowski
/--------==============--------\
| http://www.cft.edu.pl/~roman |
\--------==============--------/
 
Reply With Quote
 
Dave
Guest
Posts: n/a
 
      12-29-2005
Roman Werpachowski wrote:

> I don't understand it. I've looked for a list of reserved words in C++ and
> 'close' is not there.
>


I think you might be a bit unwise to choose a word that is not
reservered, but one might reasonably think might be in a later revision
of the dynamic C++ language. close_file is not descriptive, but less
likely to become a reservered word in the future.


--
Dave K

http://www.southminster-branch-line.org.uk/

Please note my email address changes periodically to avoid spam.
It is always of the form: month-year@domain. Hitting reply will work
for a couple of months only. Later set it manually. The month is
always written in 3 letters (e.g. Jan, not January etc)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is "www2" a sort of reserved word for path of web projects ? ("Publish website" failing without errors) craigkenisston@hotmail.com ASP .Net 1 01-19-2007 09:11 PM
Are Python's reserved words reserved in places they dont need to be? metaperl Python 32 09-15-2006 02:02 PM
RE: Are Python's reserved words reserved in places they dont needtobe? Delaney, Timothy (Tim) Python 10 09-14-2006 04:17 PM
Re: Are Python's reserved words reserved in places they dont needtobe? Steve Holden Python 0 09-13-2006 08:44 AM
[2.3] object does not appear to be a reserved word Daniel Klein Python 4 09-07-2003 01:49 AM



Advertisments