Archived

This topic is now archived and is closed to further replies.

Buggy Class or is VC++ a little lost?

This topic is 5821 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
* 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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
quote:
Original post by Magmai Kai Holmlor
use #pragma once
instead of the #ifndef trick, and you can avoid that problem in the future


I believe the #pragma trick is a VC++ specific thing and non-standard. (But I could be wrong since I'm not going to through the trouble of looking up the standard to be sure. ) Of course, this doesn't matter too much if you never plan on porting your code to another platform. It is generally bad to teach yourself non-standard ways of doing things, however.

Edited by - jaxson on January 3, 2002 4:29:11 AM

Share this post


Link to post
Share on other sites