Thread: Arrays & Classes

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    3

    Question Arrays & Classes

    Hi!I want to use an array as a class member.I wrote something like this:
    Code:
    class my_class{
          
             public:
                      ....
                      int x;
                      int array[5];
                      void function();          
                       .....
             }
    
    my_class::my_class()
    {
            ....
             x = 0;
             array[ 5 ] = { 0,1,2,3,4 };
    }
    
    void my_class::function()
    {
         for( i = 0; i < 5; i++ )
         {
               if ((something) > array[i] )
               {
                     do something.....;
                }
          }
    }
    The compiler (Dev-C++) gave an error with the message "expected priimary - expression before '{' token : in the line // array[ 5 ] = { 0,1,2,3,4 }; // of the constructor.

    Any ideas...?

    MaRaDoNa
    ========
    Last edited by maradona; 12-22-2006 at 06:29 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dynamic allocation of 2 dim. arrays in classes
    By circuitbreaker in forum C++ Programming
    Replies: 4
    Last Post: 02-10-2008, 12:13 PM
  2. Help with arrays and pointers please...
    By crazyeyesz28 in forum C++ Programming
    Replies: 8
    Last Post: 03-17-2005, 01:48 PM
  3. Questions on Classes
    By Weng in forum C++ Programming
    Replies: 2
    Last Post: 11-18-2003, 06:49 AM
  4. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 07:26 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM