Jump to content
  • Advertisement
Sign in to follow this  
mind in a box

[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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 names
If 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 undefined18

18->Thus, sequences of characters that resemble escape sequences cause undefined behavior.


For the rest of your code, read this one.




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-defined semantics,
or as is the appearance of the character " appears in a in an h-char-sequence , the behavior is undefined.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 this post


Link to post
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 <iostream>
#include <fstream>

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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by mind in a box
I 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 this post


Link to post
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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!