473,396 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Frustrating array initialization problem

I have the ff code:

class MyClass {
public:
....

private:
typedef unsigned int (*hash_func_t) (void *data);
typedef int (*comp_func_t) (void *d1, void *d2);
typedef void (*destroy_func_t) (void *data);

typedef struct {
hash_func_t hash;
comp_func_t cmp;
destroy_func_t destroy;
}TypeFuncs;

TypeFuncs const functionTable[] = { //<- Compiler barfs here
//NOP
{},
//ID_STRING
{ (hash_func_t) &str_hash, (comp_func_t) &str_cmp, (destroy_func_t),
&str_destroy },
//STRING_ID
{ (hash_func_t) &int_hash, (comp_func_t) &int_cmp, (destroy_func_t),
&int_destroy },
//CONTRACT_DETAILS
{ (hash_func_t) &contract_hash, (comp_func_t) &contract_cmp,
(destroy_func) &contract_destroy },
...
};
};

Error msg:

syntax error : '{'
error C2334: unexpected token(s) preceding '{'; skipping apparent
function body'

This is a straight forward array initialization - why am I getting
compilation errors?

Apr 17 '06 #1
1 2491
Bit byte wrote:
I have the ff code:

class MyClass {
public:
....

private:
typedef unsigned int (*hash_func_t) (void *data);
typedef int (*comp_func_t) (void *d1, void *d2);
typedef void (*destroy_func_t) (void *data);

typedef struct {
hash_func_t hash;
comp_func_t cmp;
destroy_func_t destroy;
}TypeFuncs;

TypeFuncs const functionTable[] = { //<- Compiler barfs here
//NOP
{},
//ID_STRING
{ (hash_func_t) &str_hash, (comp_func_t) &str_cmp, (destroy_func_t),
&str_destroy },
//STRING_ID
{ (hash_func_t) &int_hash, (comp_func_t) &int_cmp, (destroy_func_t),
&int_destroy },
//CONTRACT_DETAILS
{ (hash_func_t) &contract_hash, (comp_func_t) &contract_cmp,
(destroy_func) &contract_destroy },
...
};
};

Error msg:

syntax error : '{'
error C2334: unexpected token(s) preceding '{'; skipping apparent
function body'

This is a straight forward array initialization - why am I getting
compilation errors?


You can only initialize integral constants inline in a class
declaration. You'll need to make that a static const and initialize it
at the point where you define it (i.e., in the source file where you
define the class' member functions and such), or you'll need to use
another technique if making it static is not an option (cf.
http://groups.google.com/group/comp....e5982913d4414).

Cheers! --M

Apr 17 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: dam_fool_2003 | last post by:
Friends, cannot we malloc a array? So, I tried the following code: int main(void) { unsigned int y={1,3,6},i,j; for(i=0;i<3;i++) printf("before =%d\n",y); *y = 7; /* 1*/
8
by: Peter B. Steiger | last post by:
The latest project in my ongoing quest to evolve my brain from Pascal to C is a simple word game that involves stringing together random lists of words. In the Pascal version the whole array was...
15
by: Charles Sullivan | last post by:
Assume I have a static array of structures the elements of which could be any conceivable mixture of C types, pointers, arrays. And this array is uninitialized at program startup. If later in...
3
by: kk_oop | last post by:
Hi. I recently wrote a simple little template that defines an array that checks attempts to use out of bounds indexes. The only problem is that it does provide the use array style value...
5
by: toton | last post by:
Hi, I can initialize an array of class with a specific class as, class Test{ public: Test(int){} }; Test x = {Test(3),Test(6)}; using array initialization list. (Note Test do NOT have a...
3
by: sk.rasheedfarhan | last post by:
Hi , Here I am new user to C#, my problem is I have to use dynamic Array of objects. But I heard C# don't support ptrs (using managed code C# support). In short i initialized objects of 1000...
1
by: MimiMi | last post by:
I'm trying to decrypt a byte array in java that was encrypted in C#. I don't get any error messages, just a result that's completely not what I was hoping for. I think I am using the same type of...
2
by: MimiMi | last post by:
I'm trying to decrypt a byte array in java that was encrypted in C#. I don't get any error messages, just a result that's completely not what I was hoping for. I think I am using the same type of...
24
by: DomoChan | last post by:
the code below will compile in visual c++ 2003, but im not sure its valid. unsigned char myString = ""; after this line executes, all the bytes within myString are indeed set to '0's' but is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.