error C2084

This is a discussion on error C2084 within the C++ Programming forums, part of the General Programming Boards category; Hi, I am building a program in Visual C++ and I get following error: ..\..\basic.cpp(5) : error C2084: function 'int ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    62

    error C2084

    Hi, I am building a program in Visual C++ and I get following error:

    ..\..\basic.cpp(5) : error C2084: function 'int Log(char [])' already has a body
    c:\visualcpp\myprogram\basic.h(15) : see previous definition of 'Log'

    The main file includes basic.h.


    basic.h:
    Code:
    #ifndef BASIC_H
    #define BASIC_H
    #pragma once
    
    #define WIN32_LEAN_AND_MEAN
    
    #include <stdio.h>
    
    int Log(char message[]);
    #endif

    basic.cpp:
    Code:
    #include "basic.h"
    
    
    int Log(char message[])   {
    
        char log_name []= "log.txt";
        FILE *fp;
        
        fp=fopen(log_name,"a");
        fprintf(fp,"%s\n",message);
        fclose(fp);
    
    
    	return 0;
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,970
    hmm... basic.h only has 10 lines? The error is reported as being on line 15.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    62
    Quote Originally Posted by laserlight
    hmm... basic.h only has 10 lines? The error is reported as being on line 15.
    That's weird. Are they really lines? I checked and there were really only 10 lines in basic.h. There are actually a bit more lines in basic.cpp. There are a few comments.

    The original basic.cpp is here:
    Code:
    #include "basic.h"
    
    
    int Log(char message[])   {
    //
    //comments
    //
    //
    
        char log_name []= "log.txt";
        FILE *fp;
        
        fp=fopen(log_name,"a");
        fprintf(fp,"%s\n",message);
        fclose(fp);
    
    
    	return 0;
    }

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    Are you using precompiled headers?
    maybe clean and rebuild all will help?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    Registered User
    Join Date
    Aug 2006
    Posts
    62
    I tried, that doesn't help.

    I figured out, where that line 15 comes. It counts lines in basic.h until the line "int Log(char message[]);" and then counts lines forward from file basic.cpp function Log until the line
    "int Log(char message[]); {"

  6. #6
    Registered User
    Join Date
    Jan 2007
    Posts
    8
    "int Log(char message[]); {"

    get rid of the semi colon in that line and you should be okay.

  7. #7
    Registered User
    Join Date
    Aug 2006
    Posts
    62
    Quote Originally Posted by stinkipete
    "int Log(char message[]); {"

    get rid of the semi colon in that line and you should be okay.
    Sorry, I have written wrong. Where is no semi-colon.

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,337
    You need to copy / paste exactly what is in those two files without any editing to make it "pretty" or "short" for the board.

    And make sure the error messages you post are consistent with the code you post.

    Also, try a different name. It could be that Log is already defined in a standard header. It is after all a pretty common name used for both "logging" and "mathematics".
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21