Jump to content
  • Advertisement

Archived

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

Austrian Coder

Problem with template

This topic is 5290 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

Hi. I am developing on linux a plugin for an application. And i want to use a simple but powerfull loger. So i am using this:
// ==================================
//!  A log class. 
/*!
	With this nice util dxr3plugin generates and mange a log file. In this
	file the developer/enduser can find informations and can find errors,
	problems and ohter stuff.
*/
class cLog : public Singleton
{
public: 
	cLog();		// use default log file
	cLog(std::string FileName);
	
	~cLog()		{ Close(); }
	
	void SetForceFlush(const bool v)	{ m_ForeFlush = v; }
	bool GetForceFlush() const			{ return m_ForeFlush; }
	
	// nice operator overloading 
	template cLog &operator<<(const T& output)
	{
		m_LogStream << output;
		if (m_ForeFlush) m_LogStream.flush();
		return *this;
	}
	
private:
	std::ofstream	m_LogStream;
	bool			m_LogOpen;
	bool			m_ForeFlush;
	
	void Open(std::string Filename);	// with this function we open our logfile
	void Close();				// with this function we close our logfile
};
 
No i call the loger so: cLog::Instance() << (char*)"This is a test"; And i get this error:
In file included from dxr3interface.c:77:
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.2/include/g++-v3/bits/ios_base.h: In
   copy constructor `std::basic_ios
   >::basic_ios(const std::basic_ios >&)'':
dxr3singleton.h:18:   instantiated from `static T Singleton::Instance() [with T = cLog]''
dxr3log.h:28:   instantiated from `cLog& cLog::operator<<(const T&) [with T = char*]''
dxr3interface.c:77:   instantiated from here
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.2/include/g++-v3/bits/ios_base.h:668: error: `
   std::ios_base::ios_base(const std::ios_base&)'' is private
dxr3singleton.h:18: error: within this context
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.2/include/g++-v3/streambuf: In copy
   constructor `std::basic_filebuf
   >::basic_filebuf(const std::basic_filebuf >&)'':
dxr3singleton.h:18:   instantiated from `static T Singleton::Instance() [with T = cLog]''
dxr3log.h:28:   instantiated from `cLog& cLog::operator<<(const T&) [with T = char*]''
dxr3interface.c:77:   instantiated from here
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.2/include/g++-v3/streambuf:922: error: `
   std::basic_streambuf<_CharT, _Traits>::basic_streambuf(const
   std::basic_streambuf<_CharT, _Traits>&) [with _CharT = char, _Traits =
   std::char_traits]'' is private
 
What could be wrong? Thanks, for any help, Christian

Share this post


Link to post
Share on other sites
Advertisement
You'll have to post your Singleton code too.

I'm not sure why you're having problems, but I thought I'd throw in a Shameless Plug: Logging Control API

My Logging API is:
- flexible
- extensible
- thread-safe
- cross-platform
- has the ability to be compiled completely out of your application
- has neat syntax

Regards,
Jeff



[ CodeDread ]

[edited by - rypyr on May 21, 2004 12:04:33 PM]

Share this post


Link to post
Share on other sites
Ok.. here is my singleton:


template
class Singleton
{
protected :
Singleton() {}
virtual ~Singleton() {}

public:
static T GetInstance()
{
static T m_Instance;
return m_Instance;
}
};


Oh and where can i find the source of your logginsystem? Becaue you only have win dll's, but i need it for Linux.

[edited by - Austrian Coder on May 21, 2004 12:43:56 PM]

Share this post


Link to post
Share on other sites
The problem seems to stem from your Singleton-class. The Singleton''s Instance method returns T by value, which makes a copy of the T, and your cLog class contains an ostream which doesn''t have a copy-constructor. In other words, when you call cLog::Instance(), the compiler wants to create a copy of your Singleton cLog, which in turns wants to copy the std::ofstream, which fails.

Simple solution: make the Singleton''s Instance method return a T& instead of a T.
Which is something your Singleton really should do in any case, otherwise it''s not really a Singleton (everytime you call Instance now a new copy is created).

- neophyte

Share this post


Link to post
Share on other sites
I've probably missed something here, but shouldn't you be supplying a template argument such as "template < class T > "?

[edited by - xCube on May 21, 2004 1:32:22 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Austrian Coder
Oh and where can i find the source of your logginsystem? Becaue you only have win dll''s, but i need it for Linux.



Austrian Coder,

If you are interested in compiling the LoggingControl API into a shared object library, I would be interested to share the source with you. It shouldn''t be a difficult task since I already wrote the source cross-platform and did a test compile under cygwin, it''s just a matter of compiling it into a shared object library under Linux (I don''t have a Linux platform available to me). Then I can post a link to the .so file going forward.

You could go to CodeDread.com and sign up at the forums and then either PM me or post your request in here.

Regards,
Jeff



[ CodeDread ]

Share this post


Link to post
Share on other sites
quote:
Original post by xCube
I''ve probably missed something here, but shouldn''t you be supplying a template argument such as "template < class T > "?

[edited by - xCube on May 21, 2004 1:32:22 PM]


Yes, it just didn''t come out in the forums because he didn''t use the source tags. Do an edit/quote on his original post to see what I mean.


[ CodeDread ]

Share this post


Link to post
Share on other sites
@Neophyte: Thanks, now it works

@rypyr: It would be a shared object, but with full sourcecode. But as the problem is solved now, i think that i dont need your logger anymore, but thanks.

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!