dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: [RESOLVED] Visual Studio error C2371 redefinition; different basic types and C2040

  1. #1
    Join Date
    Jun 2006
    Posts
    28

    [RESOLVED] Visual Studio error C2371 redefinition; different basic types and C2040

    Hi,

    My program is huge, and I am working for a company, so I cannot paste the code.

    I am facing error C2371 (lots of them, almost every function). However, I double checked, I did not redefine.

    Does anyone know what might be the problem besides declare twice?

    Also, I am encountering error C2040, error
    'char *(int)' differs in levels of indirection from 'int ()'

    Does anyone know what might be the problem also?

    thanks a lot

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Visual Studio error C2371 redefinition; different basic types and C2040

    Quote Originally Posted by linhung
    Hi,

    My program is huge, and I am working for a company, so I cannot paste the code.
    Yes you can.

    Post code that duplicates the error message. Do you think that to duplicate a compiler error message, you must use company code to do it?
    Code:
    class foo()
    {
         int x;
    }
    There is an error -- a missing semicolon. I don't work for a company named "foo".

    Also, no one can or will guess what the problem is without code. Just posting an error message is not good enough without knowing the context of where the error was generated.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; June 14th, 2006 at 12:17 PM.

  3. #3
    Join Date
    Jun 2006
    Posts
    28

    Re: Visual Studio error C2371 redefinition; different basic types and C2040

    Thanks for the reply,

    I am sorry, but I personally don't even know how to duplicate the error because I really dont know where the error is coming from.

    I am a very new intern, and this part of program contains 10 files, while each file has about 3000-6000 lines.

    I don't even know where to start copying and pasting code.

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Visual Studio error C2371 redefinition; different basic types and C2040

    Quote Originally Posted by linhung
    Thanks for the reply,

    I am sorry, but I personally don't even know how to duplicate the error because I really dont know where the error is coming from.
    You have the line number generated from the error message, what is on that line?

    Regards,

    Paul McKenzie

  5. #5
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,497

    Re: Visual Studio error C2371 redefinition; different basic types and C2040

    A very common cause of this problem is "multiple inclusion" of header files. Check that each header file has some kind of guard that prevents it from being included multiple times - e.g.


    Code:
    // YourHeader.h
    #pragma once
    
    // Whatever else you need in the header file
    or….

    Code:
    // YourHeader.h
    #if !defined( YOUR_HEADER_FILE_INCLUDED )
    #define YOUR_HEADER_FILE_INCLUDED
    
    // Whatever else you need in the header file
    
    #endif
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  6. #6
    Join Date
    Jun 2006
    Posts
    28

    Re: Visual Studio error C2371 redefinition; different basic types and C2040

    thank you all

    The problems are solved, altho new ones arrose, but, thanks a lot!!

  7. #7
    Join Date
    Nov 2018
    Posts
    1

    Re: Visual Studio error C2371 redefinition; different basic types and C2040

    Quote Originally Posted by John E View Post
    A very common cause of this problem is "multiple inclusion" of header files. Check that each header file has some kind of guard that prevents it from being included multiple times - e.g.


    Code:
    // YourHeader.h
    #pragma once
    
    // Whatever else you need in the header file
    or….

    Code:
    // YourHeader.h
    #if !defined( YOUR_HEADER_FILE_INCLUDED )
    #define YOUR_HEADER_FILE_INCLUDED
    
    // Whatever else you need in the header file
    
    #endif


    I just thought I'd chip in with a small addition to this solution.

    Being a (very) new programmer myself, I ran into this problem and solved it after finding this thread.
    But my problem was actually slightly different. This thread made me look in my relevant header file, wherein
    I discovered that when creating a new function by using an older one as template, I had forgotten to change the
    type in the declaration.

    I guess it also says something about the dangers of copy-pasting bits of code (which a good friend of mine had
    warned me about).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)