468,513 Members | 1,403 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,513 developers. It's quick & easy.

compiler error expected primary-expression before token

32
I have the following class, the primary-expression error takes place in the constructor before "{" token where the maskval[16] array gets initialized.

any help would be appreciated

emp1953
Expand|Select|Wrap|Line Numbers
  1. class encoderclass
  2. {
  3. public:
  4.  
  5.     //vars
  6.     long maskval[16];
  7.     float bitval[15];
  8.  
  9.     //methods
  10.     short encodeCosineData(float);
  11.     float decodeCosineData(int);
  12.     encoderclass()
  13.     {
  14.     maskval[16]= {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768};
  15.  
  16.     bitval[15]    = {(1/16000),
  17.                   (1/8000),
  18.                   (1/4000),
  19.                   (1/2000),
  20.                   (1/1000),
  21.                   (1/512),
  22.                   (1/256),
  23.                   (1/128),
  24.                   (1/64),
  25.                   (1/32),
  26.                   (1/16),
  27.                   (1/8),
  28.                   (1/4),
  29.                   (1/2),
  30.                   1 };
  31.     };
  32.  
  33.  
  34. private:
  35.  
  36. protected:
  37.  
  38. };
Dec 13 '07 #1
2 12682
weaknessforcats
9,207 Expert Mod 8TB
You have to remember that constructors do not construct objects. The compiler constructs the objects by allocating memory and intializing all of the data members and then calls your constructor so you can finish up any details not already completed.

The arrays you are initializing in the constructor already exist so you cannot use array initilization syntax on them. You will need change the value of each element explicitly.
Dec 13 '07 #2
emp
32
You have to remember that constructors do not construct objects. The compiler constructs the objects by allocating memory and intializing all of the data members and then calls your constructor so you can finish up any details not already completed.

The arrays you are initializing in the constructor already exist so you cannot use array initilization syntax on them. You will need change the value of each element explicitly.

Understood, and that's the fix, thanks a bunch

emp
Dec 13 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by andy.herrera | last post: by
2 posts views Thread by Tony Wilkinson | last post: by
reply views Thread by ee02iu | last post: by
35 posts views Thread by =?Utf-8?B?UElFQkFMRA==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.