help-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A problem in using g++


From: Tom Browder
Subject: Re: A problem in using g++
Date: Mon, 2 Apr 2001 07:53:34 -0500

The variable "j" is only in scope for the for loop. When you refer to it 
afterwards, it is an
error because it hasn't been declared (and even if it had been, it would not be 
the same
j as inside the loop.  (Even though the code is not ANSI C++, if
you do want j inside the arguments to for, thereshould be a comma after the code
fragment int "i = 0".)

This will work:

int j = 0;
for (int i = 0; i < 10; ++i) {
    j = j + i;
}
return j;

Hope this helps.

Tom Browder

-----Original Message-----
From: nudthutao@sina.com <nudthutao@sina.com>
Subject: A problem in using g++


>help!help!
>I am here waiting for your great help. Thanks in advance.
>A simple program as the following:
>
>//try.cpp
>int main()
>{ 
>for(int i=0,j=0;i<10;i++) 
>j=j+i; 
>return j; 
>} 
>
>To compile it, use the command "g++ try.cpp" 
>and you will get the message like "lookup j.......obsolete variable j". No 
>executable file a.out appeared. 
>Why? How should I compile it and get the executable file without changing the 
>program itself? 
>You help will be a great favor to me. If you will, you can write to 
>"nudthutao@sina.com" 
>Also, I compiled the program both under the Redhat Linux 7.0 and Bluepoint 
>Linux 2.0, which is also base on the former, and only successed in case of 
>Bluepoint Linux 2.0. 
>How does this happen? 
>
>
>______________________________________
>
>===================================================================
>ÐÂÀËÃâ·Ñµç×ÓÓÊÏä (http://mail.sina.com.cn)
>ÍøÀïÑ°Ëýǧ°Ù¶È!ûÓÐ"ÁÄÓÑËÙÅä",ÔõÄÜ"³ÉË«³É¶Ô"? (http://newchat.sina.com.cn)
>
>_______________________________________________
>Help-gnu-utils mailing list
>Help-gnu-utils@gnu.org
>http://mail.gnu.org/mailman/listinfo/help-gnu-utils
>





reply via email to

[Prev in Thread] Current Thread [Next in Thread]