|
-
Apr 4th, 2002, 09:53 PM
#1
Thread Starter
Hyperactive Member
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!
-
Apr 4th, 2002, 10:39 PM
#2
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.
-
Apr 4th, 2002, 11:41 PM
#3
Thread Starter
Hyperactive Member
-
Apr 6th, 2002, 05:49 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|