Results 1 to 4 of 4

Thread: Contructor (initialize multi-array)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    ON, CAN
    Posts
    265

    Contructor (initialize multi-array)

    hello,

    having some difficulty here with contructors... What i'de like to do is initialize the multidimensional array with all the morse code values..

    i can initialize the array in source file ok, but when i try to initialize the same array in a class it won't work...

    I'm farily new to classes and contructors, so any explanation on what could be wrong would be great!!

    Code:
    //#include <string.h>
    #include <stdlib.h>
    
    #define MORSE = 6;
    #define ALPHA = 37;
    
    class morse
    {
    private:
    	/*char morseCode[][MORSE] = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",
    							".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",
    							".--","-..-","-.--","--..",".----","..---","...--","....-",".....",
    							"-....","--...","---..","----.","-----"};
    	*/
    	char morseCode[][MORSE];
    	char alpha[37];
    public:
    //	char getCode(char alpha);
    	morse();
    };
    morse::morse()
    {
        morseCode[][MORSE] = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",
    							".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",
    							".--","-..-","-.--","--..",".----","..---","...--","....-",".....",
    							"-....","--...","---..","----.","-----"};
    }
    
    
    thanks in advance for any help!

  2. #2
    Zaei
    Guest
    That style of initialization is illegal in classes. You are going to have to know the number of morse codes initially, and then copy them in manually(as far as I know), in the constructor.

    Z.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    ON, CAN
    Posts
    265
    thank you,

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    The main problem lies in C, not C++: The compiler doesn't know initially how large that array will be, so he can't create the compund type (class, struct or union).
    Any class/struct/union with a [] array is invalid in C/C++
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width