Buggy Class or is VC++ a little lost?

Started by
10 comments, last by reaptide 22 years, 3 months ago
Hello everyone, I''m having a bit of trouble with the log file class that I am attempting to make. I''ve gone over it a few times now and it seems to be just fine, but VC++ insists on telling my that it is messed up. Mind taking a look and teling me what''s up? The error that I am receiving is: "log.h(28) : error C2011: ''CLog'' : ''class'' type redefinition" Here is my log class:
  

// Log.h -------------------------------------------------------

#ifndef _LOG_H_
#define _LOH_H_

//--------------------------------------------------------------

// INCLUDES

//--------------------------------------------------------------

#include <windows.h>
#include <iostream.h>
#include <fstream.h>

//--------------------------------------------------------------

// CLASS - CLOG

//--------------------------------------------------------------

class CLog
{                    // Error seems to occur on this line

public:
	Create(char *Filename);
	Log(char *Message);
	Destroy();

private:
	ofstream LogFile;
};

#endif

// Log.cpp -----------------------------------------------------


//--------------------------------------------------------------

// INCLUDES

//--------------------------------------------------------------

#include <windows.h>
#include <iostream.h>
#include <fstream.h>
#include "Log.h"

//--------------------------------------------------------------

// Method: Create()

// Desc: Creates the Log File and Opens it for Writing.

//--------------------------------------------------------------

CLog::Create(char *Filename)
{
	// Open the Log File

	LogFile.open(Filename, ios::out);
}

//--------------------------------------------------------------

// Method: Log()

// Desc: Outputs the Message to the Log File.

//--------------------------------------------------------------

CLog::Log(char *Message)
{
	LogFile.write(Message, strlen(Message));
}

//--------------------------------------------------------------

// Method: Destroy()

// Desc: Closes the Log File.

//--------------------------------------------------------------

CLog::Destroy()
{
	LogFile.close();
}

  
The class is so simple that it should work rather well. Any ideas? Thanks for any help.
Advertisement
You don''t have any return types defined for the functions. When I did that it asked me to return a value because that was what it assumed the functions would do. I couldn''t regenerate that exact error from your source though.
Did you inlcude the cpp in another file? That could cause problems... Include the header and add the cpp to the project.

Magmai Kai Holmlor

"Oh, like you''ve never written buggy code" - Lee

"What I see is a system that _could do anything - but currently does nothing !" - Anonymous CEO
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
#ifndef _LOG_H_
#define _LOH_H_
Zipster''s right. You need to do something like this:
//Log.h

void Create(char *Filename); //returns void, replace with what
//you like.

//Log.cpp
void CLog::Create(char *Filename){ // Open the Log File LogFile.open(Filename, ios::out);
}

Now the function is declared correctly. It might be (?) good to change void to something like BOOL or RETCODE, just to make sure everything goes well.
- Just another sad bastard
*ahem*

Take a look at the anon post.

D.V.

Carpe Diem
D.V.Carpe Diem
* Blink, Blink *

Well I''m feeling a little stupid now. Thanks for pointing out the little mistake, it is working perfectly now. Guess I''m gonna have to smack my proofreader around a bit for missing something that simple

As well I have added return types to the member functions, better to be safe than sorry.

Thanks a lot guys.
If you don''t specify a return type, its return type is int.

Next time you post a title like this:
quote:
Buggy Class or is VC++ a little lost?

..make sure you check this page first:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q243451

If the problem isn''t listed on the page, it''s your fault.
quote:Original post by Stoffel
If you don''t specify a return type, its return type is int.


Since he is using a ''class'', then he must be using C++ and C++ requires a return type, there is no default.

quote:Quote from ''Thinking in C++ Vol 1'' by Bruce Eckel
A C++ function prototype must specify the return value type of the function (in C, if you leave off the return value type it defaults to int).


---
Make it work.
Make it fast.
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]
"C++ requires a return type, there is no default"

Absolutely incorrect

This topic is closed to new replies.

Advertisement