Path: utzoo!attcan!uunet!husc6!mit-eddie!NSWC-WO.ARPA!mlijews
From: mlijews@NSWC-WO.ARPA
Newsgroups: comp.lang.c++
Subject: Bug with const declarations.
Message-ID: <8806141821.AA03346@EDDIE.MIT.EDU>
Date: 14 Jun 88 14:57:58 GMT
Sender: rassilon@eddie.MIT.EDU
Lines: 28


     The following program is adapted from Stoustrup's book.  Shouldn't the
const int vec[] yield a warning during compilation like const int one and
shouldn't it not be posible to change vec[1] to 2?

PROGRAM:

#include 

main()
{
	const int one = 1;
	one = 2;	// error

	const int vec[] = {1,2};
	vec[1] = 2;	// should be error

	cout << "one = " << one << "\nvec[1] = " << vec[1] << "\n";
}

COMPILATION and OUTPUT:

In function int main ():
test9.cc:6: warning: assignment of read-only variable `one'

one = 1
vec[1] = 2