-
July 6th, 2001, 05:29 AM
#1
error in C++ but not in C
Hello
I have a C header file from someone else, and i need to complile with the Lib. I am using VC++ 6 and give me alot of error. Same header file, if use in C program, only warning not error.
The error is
error C2440: 'initializing' : cannot convert from 'const int' to 'MASK_TYPE'
Here i attach the header file, which is come with a lib file.
#if !defined( MASKS_DEFINED )
#define MASKS_DEFINED
typedef enum {GAUSSIAN, LOW1, LOW2, NEIGHBORHOOD, LAP1, LAP2, LAPB1, LAPB2,
SOB_V, SOB_H, W1, W2, W3, W4, W5, W6, W7, W8, W9} MASK_TYPE;
typedef struct {
short int n;
short int **vertical;
short int **horizontal;
short int **diag1;
short int **diag2;
} KIRSCH_MASK;
#define MASKS1 0, 1.0,2.0,1.0, 2.0,4.0,2.0, 1.0,2.0,1.0, \
1, 0.1,0.1,0.1, 0.1,0.2,0.1, 0.1,0.1,0.1, \
2, 1.0/16,1.0/8.0,1.0/16.0, 1.0/8.0,1.0/4.0,1.0/8.0, 1.0/16,1.0/8,1.0/16, \
3, 1.0/9.0,1.0/9.0,1.0/9.0, 1.0/9.0,1.0/9.0,1.0/9.0, 1.0/9.0,1.0/9.0,1.0/9.0, \
4, 0.0,-1.0,0.0, -1.0,4.0,-1.0, 0.0,-1.0,0.0, \
5, 1.0,-2.0,1.0, -2.0,4.0,-2.0, 1.0,-2.0,1.0, \
6, -1.0,-1.0,-1.0, -1.0,9.0,-1.0, -1.0,-1.0,-1.0, \
7, 1.0,-2.0,1.0, -2.0,5.0,-2.0, 1.0,-2.0,1.0, \
8, 1.0,0.0,-1.0, 2.0,0.0,-2.0, 1.0,0.0,-1.0, \
9, 1.0,2.0,1.0, 0.0,0.0,0.0, -1.0,-2.0,-1.0, \
10, 1.0,1.4142136,1.0, 0.0,0.0,0.0, -1.0,-1.4142136,-1.0, \
11, 1.0,0.0,-1.0, 1.4142136,0.0,-1.4142136, 1.0,0.0,-1.0, \
12, 0.0,-1.0,1.4142136, 1.0,0.0,-1.0, -1.4142136,1.0,0.0, \
13, 1.4142136,-1.0,0.0, -1.0,0.0,1.0, 0.0,1.0,-1.4142136, \
14, 0.0,1.0,0.0, -1.0,0.0,-1.0, 0.0,1.0,0.0, \
15, -1.0,0.0,1.0, 0.0,0.0,0.0, 1.0,0.0,-1.0, \
16, 1.0,-2.0,1.0, -2.0,4.0,-2.0, 1.0,-2.0,1.0, \
17, -2.0,1.0,-2.0, 1.0,4.0,1.0, -2.0,1.0,-2.0, \
18, 1.0,1.0,1.0, 1.0,1.0,1.0, 1.0,1.0,1.0
#define MASKS2 0, 1.0/25,1.0/25,1.0/25,1.0/25,1.0/25, \
1.0/25,1.0/25,1.0/25,1.0/25,1.0/25, \
1.0/25,1.0/25,1.0/25,1.0/25,1.0/25, \
1.0/25,1.0/25,1.0/25,1.0/25,1.0/25, \
1.0/25,1.0/25,1.0/25,1.0/25,1.0/25
static struct mask3x3 {
MASK_TYPE choice;
float kernel[9];
} MASK3x3[] = {MASKS1}; //1st ERROR is HERE
static struct mask5x5 {
MASK_TYPE choice;
float kernel[25];
} MASK5x5[] = {MASKS2};
extern Image * h_image(int type, unsigned int height, unsigned int width);
#endif /* MASKS_DEFINED */
Sooner Or Later, Everyone Does...
-
July 6th, 2001, 07:22 AM
#2
Re: error in C++ but not in C
why you not replace 0 by GAUSSIAN etc. into #define?
t!
-
July 6th, 2001, 08:13 AM
#3
Re: error in C++ but not in C
It might be possible the syntax of defining few types might be different.try using.
#ifdef __cplusplus
extern "C" {
#endif
your .h file
#ifdef __cplusplus
}
#endif
bye now
-
July 6th, 2001, 10:07 AM
#4
Re: error in C++ but not in C
Replace the first 0 in MASKS1 and MASKS2 definition to GAUSSIAN and it should work...
#define MASKS1 GAUSSIAN, 1.0, 2.0, ....
....
#define MASKS2 GAUSSIAN, 1.0/25,1.0/25, ....
....
Martin
-
July 8th, 2001, 06:50 PM
#5
Re: error in C++ but not in C
Thanks for you suggestion, but it is not working.
The error still there. Any other idea?
TQ
Sooner Or Later, Everyone Does...
-
July 8th, 2001, 06:56 PM
#6
Re: error in C++ but not in C
Thanks for your reply, but i don't really understand how to do this. Can you please explain this in detail? TQ
Sooner Or Later, Everyone Does...
-
July 8th, 2001, 07:19 PM
#7
Re: error in C++ but not in C
It is obvious what the error is.
#define MASKS1 0, // etc...
1, // etc...
2, // etc...
The 0, 1, 2, 3, etc. in your #defines MASKS1 can't be used. Why? Because C++ is looking for a MASK_TYPE, not an integer. Look at your structure:
static struct mask3x3 {
MASK_TYPE choice; // <<-- This *must* be a MASK_TYPE, not an integer!
float kernel[9];
} MASK3x3[] = {MASKS1};
You are attempting to initialize the array of structures with an integer followed by 9 floats. But the structure plainly states a MASK_TYPE followed by 9 floats. Therefore replace all of your 0, 1, 2, 3, etc. in your #define MASKS1 with GAUSSIAN, LOW1, LOW2, etc. You did define them, so why don't you use them?
Regards,
Paul McKenzie
-
July 8th, 2001, 08:09 PM
#8
Re: error in C++ but not in C
As a result of improved C++ conformance, some constructs that used to compile will now give errors. One compilation error that has changed is c2440. In C you were able to implicitly cast an integer to an enum, this is no longer possible. The solution to your problem is one out of two:
1. Use the name of the enum instead of the constant:
#define MASKS1 GAUSSIAN,... LOW1,...LOW2
2. explictly cast the integer to the enum
#define MASKS1 (MASK_TYPE)0,... (MASK_TYPE)1,...(MASK_TYPE)2
note that the former is the prefered method because it is type safe, and you won't get any errors caused by casting an integer to a value the enum doesn't contain(W9 + 1).
Got a question? try looking it up in MSDN first. Msdn comes with the Visual Studio, and can be found at http://msdn.microsoft.com
---===---
I'm not here for the rates, but rating a post is a good way for me to know how much i helped.
---===---
Daniel
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
|