Jump to content
  • Advertisement

Archived

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

reaptide

Buggy Class or is VC++ a little lost?

This topic is 6042 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
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.

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
Guest Anonymous Poster
#ifndef _LOG_H_
#define _LOH_H_

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!