Click to See Complete Forum and Search --> : Compile C++ with Visual C++.NET


Anata
July 22nd, 2005, 07:02 AM
My program use a class wmutility that write by standard C++.
wmutility class:

#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <math.h>

#include <string>
#include <iostream>
using namespace std;

#include "wmutility.h"

int make_ww( )
{
string strTemp;
........................
}

...............

I compile program by Visual C++.NET. I get a lot of errors.
I think It error at here.

#include <string>
using namespace std;

Compiling...
wmutility.cpp
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(862) : error C2143: syntax error : missing ';' before '<'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(935) : see reference to class template instantiation 'std::istreambuf_iterator<_Elem,_Traits>' being compiled
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(862) : error C2238: unexpected token(s) preceding ';'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(863) : error C2143: syntax error : missing ';' before '<'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(863) : error C2238: unexpected token(s) preceding ';'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(866) : error C2143: syntax error : missing ')' before '*'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(866) : error C2143: syntax error : missing ';' before '*'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(866) : error C2864: '_Sb' : only const static integral data members can be initialized inside a class or struct
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(866) : error C2501: 'std::istreambuf_iterator<_Elem,_Traits>::_Sb' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(866) : error C2143: syntax error : missing ';' before 'throw


Please help me!
thank you very much!

Kheun
July 22nd, 2005, 07:33 AM
It looks like there are syntax errors in wmutility.h or wmutility.cpp. If allowed, you may like to show us the codes in both files so that we can compile to see what happen.

Anata
July 22nd, 2005, 07:54 AM
Thank for your reply!

This is wmutility.h and wmutility.cpp
(It very long, so i extract it)
wmutility.h

#ifndef __MEMORY_ALLOC_H__
#define __MEMORY_ALLOC_H__


#define IMAGE( x, y, z ) ( *( image + ( (x) + (y)*width )*3 + (z) ) )
#define IMAGE_BMP( x, y, z ) ( *( image + (x)*3 + (y)*ww + (z) ) )
template <class T>
inline bool alloc_memory_2d( T**& mem, const int m, const int n )
{
if ( m <= 0 || n <= 0 )
{
return false;
}

if ( ( mem = (T**)malloc(sizeof(T*) * m ) ) == NULL )
{
return false;
}

if ( mem != NULL )
{
for ( int i = 0; i < m; i++ )
{
if ( ( mem[i] = (T*)malloc(sizeof(T) * n) ) == NULL )
{
return false;
}
}
}

return true;
}

extern int bmp_flag;

int make_ww( int width );
int bgr2rgb( unsigned char* rgb, int width, int height, int color );

#endif // __MEMORY_ALLOC_H__


wmutility.cpp

#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <math.h>

#include <string>
using namespace std;

#include "wmutility.h"

int make_ww( int width )
{
return ((24 * width + 31) & ~31) / 8;
}

int liner_trans_y( unsigned char* image, int width, int height, int color, int max, int min )
{
int i, j, pix;
double a, b;

int ww = make_ww( width );

if( max > 255 || max < 0 ) return -1;
if( min > 255 || min < 0 ) return -1;
if( max <= min ) return -1;

a = (double)(max-min)/255.;
b = min;

// fprintf( stdout, "a = %f \n", a );
// fprintf( stdout, "b = %f \n", b );

for( j = 0; j < height; j++ )
{
for( i = 0; i < width; i++ )
{
if( bmp_flag == 1 ) {
pix = (int)( a*(double)IMAGE_BMP( i, j, 0 ) + b );
} else {
pix = (int)( a*(double)IMAGE( i, j, 0 ) + b );
}

if( pix > max ) pix = max;
if( pix < min ) pix = min;

if( bmp_flag == 1 ) IMAGE_BMP( i, j, 0 ) = pix;
else IMAGE( i, j, 0 ) = pix;
}
}

return 0;
}

Some funtion use string, but it very long.
I think that, it errors when use namespace in Visual C++.NET.
When i don't use "#include <string>
using namespace std;" it non errors.
What is use to supersede string if don't use string?

NMTop40
July 22nd, 2005, 08:13 AM
Hey this needs an enormous amount of redesign.

(And you should use code tags).

- Why are you mixing C in with C++? If you are programming in C you can't use templates or <string> but if you are coding in C++ you should generally not be using malloc(). And where exactly does that memory get freed? There is no matching free() for the malloc().

- Don't use macros. Inline functions are better.

- As you are obviously using a 2-d array, have a look at my Matrix class in the FAQ. (Actually I have a much more sophisticated one I use in reality). The basics though is to use std::vector< T > to store the data where the size of the vector is M * N and you access an element with operator() thus

mat( 2, 5 );

where "mat" is the instance of a matrix.

Note: My matrix also allows you to extract the raw pointers for manipulation and I have a function to multiply matrix * matrix and matrix * vector which use direct pointer manipulation because they proved to be 3-times faster.

NMTop40
July 22nd, 2005, 08:34 AM
Don't cross-post. You posted this also in VC++ (non-visual issues).

But if you compile in Visual Studio .NET then go to the Output tab and you'll get more detail of your errors, and can usually trace them to a line in your own code.

Andy Tacker
July 22nd, 2005, 08:49 AM
merged threads...

Anata
July 22nd, 2005, 10:38 PM
Thank you!
I will redesign.