Archived

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

Zidane

Confused ....

Recommended Posts

I have a very simple class, the prototype of which is shown below:

namespace Eden {


// log file results
typedef enum tagLogFileResult{LOGFILE_ERROR=0,
							  LOGFILE_OK,
							  LOGFILE_COULDNOTWRITE,
							  LOGFILE_COULDNOTOPEN} LogFileResult;

// EDEN_API = __declspec(dllexport) for compiling engine
// and __declspec(dllimport) for users of the engine
class EDEN_API CLogFile
{
private:
	std::ofstream OutputFile;
public:
	/*CLogFile(const CLogFile&);
	CLogFile();
	~CLogFile();*/
	LogFileResult Open(const std::string c_FileName_);
	void Close();			
	LogFileResult Write(const EdenChar *cp_acMsg_, ...);
};

}

[/CODE]

The compiler (Visual C++ 7) will not generate an asignment operator & copy functions for this class. Which basically means i cant even go

LogFile1 = LogFile2 

And this is stopping me using a vector for holding an varying size array of log files which is what my object manager needs to do ... 

Now I have much more complex classes in the engine and the compiler seems to have 0 problems whith generating the operators and methods for those.

So fearing some bug in my compiler i wrote my own copy constructor and I get the following error:

c:\MikesStuff\Programming\Eden\engine\CLogFile.cpp(53): error C2582: ''operator ='' function is unavailable in ''std::basic_ofstream<_Elem,_Traits>''
        with
        [
            _Elem=char,
            _Traits=std::char_traits
        ]

Is this a design trait of ofstream that you cant assign it to another ofstream or is it my compiler being a little strange or me just being a crap programmer ?

Ok I AM using the multi threaded debug dll libaries so the fact that the class resides in a dll and the usage is in a win32 app shouldnt be a problem should it?

If I am just misunderstanding basic c++ please say so and tell me off . This is my first major project using Visual C++ compiler so... 

Thanks in advance.


   

Share this post


Link to post
Share on other sites
streams do not have assignment or copy constructors defined, simply because there''s no conceptually reasonable way to duplicate an object that refers to a non-duplicatable resource (like the console).

You COULD use a reference-counted scheme, and have a pointer to the ofstream. Look into the smart pointer classes at http://www.boost.org.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites