# [C++] Incomplete type error

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

## Recommended Posts

So I wanted to write my own cool timer which supports the calling of member functions.

I used the boost::function before and it worked very well, but this time I get an "Incomplete type"-error when using it.

My code goes as following:
#include <boost\functional.hpp>#include <boost\function.hpp>#include <boost\bind.hpp>/** Timer which ....    ... */class MemberFunctionTimer{public:	MemberFunctionTimer(void);	virtual ~MemberFunctionTimer(void);	/** Gives a function to this class. It will be called when the timer executes */	void Init(boost::function<void> Callback, float TimeToRun) // <----- Errors here!	{		CallbackFunction=Callback;		this->TimeToRun=TimeToRun;	}//...

Someone sees what I forgot?

##### Share on other sites
void isn't a valid function signature. Did you mean boost::function<void (void)>?

##### Share on other sites
That did it!

I always had return values when I used boost::function before, so I may confused that.

##### Share on other sites
Quote:
 boost\bind.hpp

Note that directories in filenames in C and C++ are seperated with a slash, not with a backslash. Backslashes in #include filenames yield undefined behaviour:

Quote:
 2.9 Header namesIf either of the characters ’ or \, or either of the character sequences /* or // appears in a q-char-sequence or a h-char-sequence, or the character " appears in a h-char-sequence, the behavior is undeﬁned1818->Thus, sequences of characters that resemble escape sequences cause undeﬁned behavior.

edit: I realise they have updated it (above was from n3000, this is from n3090)
Quote:
 If The appearance of either of the characters ’ or \, or of either of the character sequences /* or // appears in a q-char-sequence or a an h-char-sequence is conditionally supported with implementation-deﬁned semantics,or as is the appearance of the character " appears in a in an h-char-sequence , the behavior is undeﬁned.18

The footnote says that depending on your compiler, this might be an error, an escape sequence, or something completely different (e.g. a windows path name under MSVC). Still, I think implementation-defined is not much better than undefined for non-systems-programmers, so I'd highly discourage this and use the well-defined slash instead.

##### Share on other sites
Quote:
 Note that directories in filenames in C and C++ are seperated with a slash, not with a backslash. Backslashes in #include filenames yield undefined behaviour:

Never got problems with this ... But just to stay save I'll change the slashes when everywhere when I used them (Just a very few times).

Quote:
 #include #include int main() { #if 1 std::ifstream file("../test.dat"); // RIGHT! #else std::ifstream file("..\test.dat"); // WRONG! #endif ... }

I used this when dealing with files. Is it okay or will it break at some time?
std::ifstream file("..\\test.dat");

Edit: I just read the bottom of your linked FAQ. According to this, I may want to run a "Replace all" over my code and replace all "\\" with a "/".

##### Share on other sites
Quote:
 I used this when dealing with files. Is it okay or will it break at some time?std::ifstream file("..\\test.dat");

I guess it is okay as long as you don't leave windows, even though it is not the proper way. Personally, if I can have cross-platformness for free, then I grab it. Read: I never went back to backslashes :D

Note though that, imho, it is also more error prone, a backslash might be forgotten, but the path still looks correct upon code review.

##### Share on other sites
Quote:
 Original post by mind in a boxI used this when dealing with files. Is it okay or will it break at some time?std::ifstream file("..\\test.dat");
It will work fine on Windows, and not anywhere else.

If you are just writing software for windows, then there isn't any real harm in it, but '/' works everywhere, and is much less confusing to deal with (how many backslashes are needed to sprintf a backslash to a string and later use it with printf?).

##### Share on other sites
Forward slashes are safer because it is harder to accidentally do the following:
std::ofstream stream("C:\new.txt"); // whoops, that is a newline character!

• 9
• 23
• 10
• 19