CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2005
    Posts
    1,030

    Why there is not any compiler errors?

    Here is code,
    Code:
    void foo(int x);
    void foo(int x);
    
    int main()
    {
    	return 0;
    }
    I would expect that there is compiler error for multiple definitions of function foo. But it turns out to be just fine. Why? Thanks.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: Why there is not any compiler errors?

    There are not the definitions but declarations.
    Try to define (implement) this function.
    Victor Nijegorodov

  3. #3
    Join Date
    Nov 2002
    Location
    Sofia, Bulgaria
    Posts
    661

    Re: Why there is not any compiler errors?

    Basically you're declaring the same function and not using it. Here's what the build process will "say" for your code (comments):

    Code:
    void foo(int x); // there is a function named foo
    void foo(int x); // there is a function named foo (I already know that, but it doesn't matter)
    
    int main()
    {
    	// ok... do nothing
    	return 0;
    }
    
    // the function foo was never used, so I don't need anything more
    If you had called foo in main (say foo(42), there would have been a linker error.
    It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured