Thread: declare consts~

  1. #1
    flashing vampire black's Avatar
    Join Date
    May 2002
    Posts
    563

    Arrow declare consts~

    Howdy everyone.

    an simple question. I declare the const like this:

    const int x;
    x=0;

    but it failed when compiling. Could we declare the const first and valued it later ?
    Never end on learning~

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Constants are declared like this.
    const int x = 0;

    What you did was say, i want this integer x to be constant. Then the compiler says ok, now nothing can change it. Then you said i want to change it now to 0. That is why it didn't let you, you cannot do that with 2 statements like you have. Put them all on the same one and you will be fine.

  3. #3
    flashing vampire black's Avatar
    Join Date
    May 2002
    Posts
    563

    Wink

    Originally posted by MrWizard
    Constants are declared like this.
    const int x = 0;

    What you did was say, i want this integer x to be constant. Then the compiler says ok, now nothing can change it. Then you said i want to change it now to 0. That is why it didn't let you, you cannot do that with 2 statements like you have. Put them all on the same one and you will be fine.
    got it, thanx.
    Never end on learning~

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to declare a global input stream
    By Chazij in forum C++ Programming
    Replies: 2
    Last Post: 11-18-2008, 04:53 PM
  2. Programmatically declare vectors
    By franse in forum C++ Programming
    Replies: 15
    Last Post: 11-10-2008, 03:17 PM
  3. How to declare a list in another list???
    By zaracattle in forum C++ Programming
    Replies: 1
    Last Post: 10-24-2006, 08:24 AM
  4. how to declare overloaded function that has 2 parameters?
    By zaracattle in forum C++ Programming
    Replies: 2
    Last Post: 10-11-2006, 07:56 AM
  5. Declare a template class as a friend?
    By AH_Tze in forum C++ Programming
    Replies: 11
    Last Post: 05-19-2004, 09:24 PM