Advertisement

recursive control paths (wtf?)

Started by January 27, 2001 01:43 PM
3 comments, last by Countach 24 years ago
I''ve been getting a really weird error message lately: warning C4717: ''Console::Output::operator='' : recursive on all control paths, function will cause runtime stack overflow So it sounds like something bad oughta happen but surprisingly all code executes without any problems. The class is a simple derived class of Log::Output which routes logged messages, it has no members only a vtable:
  
// Console - Command line interface to engine internals

class tremorapi Console {
	public:
		// Output class to route logged messages to the console

		// Usage: Log::instance->outputTo(new Console::Output);

		class tremorapi Output : public Log::Output {
			public:
				void write(const char *function, const char *message);
				Log::Output *clone() const;
		};
        // ...

};

class tremorapi Log {
	public:
		// Output for log messages baseclass

		class tremorapi Output {
			public:
				virtual void write(const char *function, const char *message) = 0;
				virtual Output *clone() const = 0;

				virtual ~Output(){}
		};
         // ...

}
  
Any hints to what this might mean are welcome.
-------homepage - email
Anyone?
-------homepage - email
Advertisement

Do you actually call the function Console Log::Output clone function ?...I guess it could be that which the compiler thinks is recursive.....

Actually, what does the line:
Log::Output *clone() const;
do exactly ? Shouldn''t it just be Output *clone() const; ?

I think what the compiler is complaining about is that, if you call the virutal function Log::Output->clone, that will call the corresponding clone function in the derived class, which happens to be the same Log::Output->clone function, so it is recursive.....I think.....


btw You''re defining classes within other classes and then wondering why you get confusing error messages ? Would it really be impossible to have the Output class outside of the Log class ? and having two classes called Output is really, really confusing....






Game production:
Good, quick, cheap: Choose two.
Game production:Good, quick, cheap: Choose two.
quote:

Do you actually call the function Console Log::Output clone function ?...I guess it could be that which the compiler thinks is recursive.....



I don''t call it explicitly but the log class accesses it through the vtable (polymorhism rules).
Anyway, thats not it. I have three other Log::Output derived classes and I don''t get the warning for them.

quote:

Actually, what does the line:
Log::Output *clone() const;
do exactly ?


The code is:
Log::Output *Console::clone() const { return new Console::Output; }
In other words it returns a new instance.

quote:

Shouldn''t it just be Output *clone() const; ?


No, the baseclass requires the return type to be Log::Output*

quote:

I think what the compiler is complaining about is that, if you call the virutal function Log::Output->clone, that will call the corresponding clone function in the derived class, which happens to be the same Log::Output->clone function, so it is recursive.....I think.....


No, the Log::Output::clone function is not called by Console::Output::clone.

quote:

btw You''re defining classes within other classes and then wondering why you get confusing error messages ? Would it really be impossible to have the Output class outside of the Log class ? and having two classes called Output is really, really confusing....


Ever heard of namespace pollution?
Thats why Im defining classes in classes.
Giving them the same name is only natural (or at least, it is to me).

Anyway, this warning is really ticking me off.
I know I can disable it, but I am still not sure if something in my code is messed up.

Did anyone else have this warning before?
If so, what did you do to make it go away?
-------homepage - email
Well I guess its just a bug or something.
The warning goes away if I add an empty copy operator.
I would never copy the class anyway so it doesn''t really matter I guess.
-------homepage - email

This topic is closed to new replies.

Advertisement