CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Installing SQL Server 2008
  • Writing UDFs for Firebird Embedded SQL Server
  • [Updated] Shutdown Manager
  • Building Windows Azure Cloud Service Applications with Azure Storage and the Azure SDK

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Managed C++ and C++/CLI
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Managed C++ and C++/CLI Discuss Managed C++ and .NET-specific questions related to C++.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old July 22nd, 2005, 07:02 AM
    Anata Anata is offline
    Junior Member
     
    Join Date: Jul 2005
    Posts: 3
    Anata is an unknown quantity at this point (<10)
    Compile C++ with Visual C++.NET

    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!
    Reply With Quote
      #2    
    Old July 22nd, 2005, 07:33 AM
    Kheun Kheun is offline
    Elite Member
     
    Join Date: Oct 2002
    Location: Singapore
    Posts: 3,124
    Kheun is a name known to all (1000+)Kheun is a name known to all (1000+)Kheun is a name known to all (1000+)Kheun is a name known to all (1000+)Kheun is a name known to all (1000+)Kheun is a name known to all (1000+)Kheun is a name known to all (1000+)Kheun is a name known to all (1000+)
    Re: Compile C++ with Visual C++.NET

    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.
    Reply With Quote
      #3    
    Old July 22nd, 2005, 07:54 AM
    Anata Anata is offline
    Junior Member
     
    Join Date: Jul 2005
    Posts: 3
    Anata is an unknown quantity at this point (<10)
    Re: Compile C++ with Visual C++.NET

    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?
    Reply With Quote
      #4    
    Old July 22nd, 2005, 08:13 AM
    NMTop40's Avatar
    NMTop40 NMTop40 is offline
    Elite Member
    Power Poster
     
    Join Date: Oct 2000
    Location: London, England
    Posts: 4,773
    NMTop40 has much to be proud of (1500+)NMTop40 has much to be proud of (1500+)NMTop40 has much to be proud of (1500+)NMTop40 has much to be proud of (1500+)NMTop40 has much to be proud of (1500+)NMTop40 has much to be proud of (1500+)NMTop40 has much to be proud of (1500+)NMTop40 has much to be proud of (1500+)NMTop40 has much to be proud of (1500+)NMTop40 has much to be proud of (1500+)NMTop40 has much to be proud of (1500+)
    Re: Compile C++ with Visual C++.NET

    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
    Code:
    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.
    Reply With Quote
      #5    
    Old July 22nd, 2005, 08:34 AM
    NMTop40's Avatar
    NMTop40 NMTop40 is offline
    Elite Member
    Power Poster
     
    Join Date: Oct 2000
    Location: London, England
    Posts: 4,773
    NMTop40 has much to be proud of (1500+)NMTop40 has much to be proud of (1500+)NMTop40 has much to be proud of (1500+)NMTop40 has much to be proud of (1500+)NMTop40 has much to be proud of (1500+)NMTop40 has much to be proud of (1500+)NMTop40 has much to be proud of (1500+)NMTop40 has much to be proud of (1500+)NMTop40 has much to be proud of (1500+)NMTop40 has much to be proud of (1500+)NMTop40 has much to be proud of (1500+)
    Re: Compile C++ with Visual C++.NET

    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.
    Reply With Quote
      #6    
    Old July 22nd, 2005, 08:49 AM
    Andy Tacker Andy Tacker is offline
    More than "Just Another Member"
     
    Join Date: Jun 2001
    Location: 55°50' N 37°39' E
    Posts: 1,503
    Andy Tacker  is a jewel in the rough (300+)Andy Tacker  is a jewel in the rough (300+)Andy Tacker  is a jewel in the rough (300+)Andy Tacker  is a jewel in the rough (300+)
    Re: Compile C++ with Visual C++.NET

    merged threads...
    __________________
    If you think you CAN, you can, If you think you CAN'T, you are probably right.

    Have some nice Idea to share? Write an Article Online or Email to us and You may WIN a Technical Book from CG.
    Reply With Quote
      #7    
    Old July 22nd, 2005, 10:38 PM
    Anata Anata is offline
    Junior Member
     
    Join Date: Jul 2005
    Posts: 3
    Anata is an unknown quantity at this point (<10)
    Re: Compile C++ with Visual C++.NET

    Thank you!
    I will redesign.
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Managed C++ and C++/CLI


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 11:34 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Copyright WebMediaBrands Inc. 2002-2009