Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Flash619

Pages: 1 2 [3] 4 5 ... 10
31
General / Re: VS 11, and variadic templates with std::thread
« on: November 06, 2012, 05:53:35 pm »
The time you waste pointlessly in "fixing" and asking in forums would be much better invested in reading books. Of course, not everybody learns well from books, but don't use this as an excuse -- there is no way around theory if you want to write good code :)

I don't expect you to learn about Boost.Function and Boost.Bind, that is why I wrote "the first point is enough". Function objects is really something every C++ programmer should know, so take the time to learn it. This is not something you use once for the thread and then never again, functors will certainly prove useful. Already because STL algorithms operate on them.

Well of course I want to learn just about everything eventually. But for now I'm trying to focus on why my thread won't work. Yea trial and error is a pain. But how else would I ever find out things don't work that way? Sure I can learn a bunch about functors, but it wont actually come out and tell me "this is why your thread is not working." So if I don't understand how the thread is supposed to work, and why my threads arguments are not working now, it would just teach me about functors, then afterwords, I would be in the same situation I am now, only I would know functors. Make sense?

32
General / Re: VS 11, and variadic templates with std::thread
« on: November 06, 2012, 05:31:02 pm »
It doesn't make sense to explain specific parts such as std::ref() if you haven't understood the whole concept of functionals.

But I'm not really asking to know about std::ref(), just really focusing on how I can actually get my thread to start up so it doesn't take me 15 hours to get a simple loading screen setup. >_> *and trust me, it probably will take longer than that*.

I'm really just trying to figure out, how to make the lovely "error C2064: term does not evaluate to a function taking 2 arguments" that has been bugging my error log for the last 45min, go away. Sure it would be awesome to sit down with a huge book about functionals and references, and binding objects. But I usually learn things backwards. *mainly because I cant actually retain knowledge from reading books *like in my sociology class* * So forgive me if I seem like I'm rushing in, I'm really not. Well, to me I'm not anyways.

Usually my process is as follows:
  • Start programming.
  • Run into an error.
  • Spend a while fixing the error.
  • Finally find a workable solution to the error.
  • Inspect how the solution works.
  • Do research as to why it works, and how it works.
  • Remember it for the future.
  • Continue programming.

That pretty much sums up how I learn things, and retain the information.

33
General / Re: VS 11, and variadic templates with std::thread
« on: November 06, 2012, 05:15:23 pm »
Yes, I spoke about std::bind and the fact that you have to pass the this pointer of the object on which you want to call the member function.
...Do you mean something like this?
std::thread RunningLoadingScreen(std::bind(&LoadingScreens::RunLoadingScreen,CurrLoadScreen,glWindow));
 

A better idea would be to learn it ;)
See the documentation of Boost.Bind, for example.
But what does Boost.Bind have to do with std::ref ? o.O;

I tried shoving in std::ref() like:
std::thread RunningLoadingScreen(&LoadingScreens::RunLoadingScreen,std::ref(CurrLoadScreen,glWindow));
 

Just to see what would happen, but it tells me that it does not match the arguments list. *I figured something like that would happen, but I had to try.*

By the way, instead of bind(), you can achieve the same functionality with a functor (=function object). It is simpler if you don't know the standard library functionals, but it requires more code.

I would rather just *try* to learn the usual way of doing it instead of having to go even further around obstacles. That's why it probably seems like I'm asking stupid questions. XD I'll admit I don't know everything. >_>

EDIT

Also I tried multiples of std::ref to try to find the proper argument method.
std::thread RunningLoadingScreen(&LoadingScreens::RunLoadingScreen,std::ref(CurrLoadScreen),std::ref(glWindow));
 

Seems to make it quiet down, but I'm almost certain its incorrect, and it still gives me the "does not evaluate to a function taking two arguments" error.

34
General / Re: VS 11, and variadic templates with std::thread
« on: November 06, 2012, 04:52:03 pm »
How did you try bind()? Did you include <functional>?

The this pointer must be specified to bind a member function to an object, and references must be passed via std::ref.
In that last part.... are you talking about "std::bind" when you talk about it being specified to bind a member function?


I had seen examples of people who recommended the use of "std::bind" but was unaware of the use of "<functional>" template. I also did see some people use "std::ref" but I was, and still do not know the proper usage of it, so I stayed away from it.

Also, according to several online tutorials that I found, this is a correct method of doing it, but it seems I have to change it to different methods for VS.  Right here, is a perfectly good example that when I try to implement it for my uses, does not work. I will note however, that they did show the use of "std::bind". They also showed that it was not required but I don't think they listed what IDE/compiler they used.

35
General / Re: VS 11, and variadic templates with std::thread
« on: November 06, 2012, 04:38:15 pm »
So I wanted to ask if there is any way around this?
std::bind()

Easiest solution: stop using VS.
I have yet to find an IDE that can compete with Visual Studio + Visual Assist X ;)

Bind() I have tried, it throws about 14 errors. ^^;;;;

Running it like:

std::thread RunningLoadingScreen(std::bind(&LoadingScreens::RunLoadingScreen,CurrLoadScreen,glWindow));
 

Quote
Error   3   error C2064: term does not evaluate to a function taking 2 arguments   C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\functional   1152   1   Genesis (Microsoft Visual C++ Compiler Nov 2012 CTP)

Running it like:
std::thread RunningLoadingScreen(&LoadingScreens::RunLoadingScreen,CurrLoadScreen,glWindow);
 

Quote
Error   3   error C2064: term does not evaluate to a function taking 2 arguments   C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\functional   1152   1   Genesis (Microsoft Visual C++ Compiler Nov 2012 CTP)

Running it like:

std::thread RunningLoadingScreen(std::bind(LoadingScreens::RunLoadingScreen,CurrLoadScreen,glWindow));
 

Quote
Error   102   error C1003: error count exceeds 100; stopping compilation.

............Not sure what to use for threading now...I really would want to use std::thread if I can, but it would seem that's a impossibility at this point.

36
General / Re: VS 11, and variadic templates with std::thread
« on: November 06, 2012, 04:31:52 pm »
The compiler explicitely gives the solution
Quote
use '&LoadingScreens::RunLoadingScreen' to create a pointer to member

That leads me to this error:
Quote
Error   3   error C2064: term does not evaluate to a function taking 2 arguments   C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\functional   1152   1   Genesis (Microsoft Visual C++ Compiler Nov 2012 CTP)

I think my problem is in how I laid out my arguments for the thread. This is the first time I have ever touched std::thread, so I really don't know what it wants me to do at this point. Every tutorial I find online, theirs works just fine. >.>

37
General / Re: VS 11, and variadic templates with std::thread
« on: November 06, 2012, 04:03:45 pm »
So an update with the Nov compiler, now I get an error telling me:

Quote
Error   1   error C3867: 'LoadingScreens::RunLoadingScreen': function call missing argument list; use '&LoadingScreens::RunLoadingScreen' to create a pointer to member

........I don't see how its missing a argument list... I passed arguments with the thread.

38
General / Re: VS 11, and variadic templates with std::thread
« on: November 06, 2012, 03:53:47 pm »
It seems that the november version of the compiler adds support for variadic templates
http://blogs.msdn.com/b/vcblog/archive/2012/11/02/visual-c-c-11-and-the-future-of-c.aspx

But if I switch my compiler, I don't think I'll be able to compile for windows XP anymore as I had it set to "Visual Studio 2012 - Windows XP (v110_xp)

>.<

I am not sure if this version of the compiler "120_CTP" includes XP support.

39
General / Re: AW: VS 11, and variadic templates with std::thread
« on: November 06, 2012, 03:39:46 pm »
Easiest solution: stop using VS. ;)
I've pretty much abandoned VS since they feel like C++11 is nothing urgent...

Otherwise you can create a struct/class that hold all your wanted data and pass everything as one argument.

Btw for generic C++/programming question I can suggest to you StackOverflow. There you'll get answers quickly and often from people with quite a bit experience.

What would you recommend instead of VS?

I've seen good and bad reports for netbeans, and I have also heard good things from eclipse *and use eclipse for java* but have no experience with it for C++

I've also heard mixed reports for code blocks.

40
General / VS 11, and variadic templates with std::thread
« on: November 06, 2012, 02:50:24 am »
This is not related to SFML, but I don't belong to any other coding community so I thought I would ask here. ^_^

I am trying to start up a thread with "std::thread" like:

std::thread RunningLoadingScreen(RunLoadingScreen,CurrLoadScreen,glWindow);
 

The function looks like:

void LoadingScreens::RunLoadingScreen(LoadingScreen LS,EngineWindow& glWindow)
{
        if(LS.IsStatic){
                sf::Sprite LSS;
                LSS.setTexture(texture.getTexture(LS.ResourcePath));
                LSS.setPosition(glWindow.GetCenter().x,glWindow.GetCenter().y);
                glWindow.draw(LSS);
                glWindow.display();
        }else{
                        sfe::Movie LSM;
                        if(!LSM.openFromFile(LS.ResourcePath))
                        {
                                return;
                        }
                        LSM.setPosition(glWindow.GetCenter().x,glWindow.GetCenter().y);
                        LSM.play();
                        while(IsLoading)
                        {
                                glWindow.draw(LSM);
                                glWindow.display();
                        }
        }
}
 

But my compiler always spits the error:

Quote
std::thread::thread No overloaded function takes three arguments.

I looked it up and apparentlyVS 11 does not support Variadic Templates. So I wanted to ask if there is any way around this? I found some people mentioning the use of adding "#define" to define stuff for the preproccesor but I was unable to make out exactly what it was they were talking about, or how to do it.

So any help is as always, 100% appreciated. If you need any info just ask! :) I look forward to a great discussion.  ;D

41
General / Re: References returning null values?
« on: November 02, 2012, 08:36:22 pm »
Yes. So you return a copy. References are for things that are heavy to copy or for input values to functions.

Oh that makes sense. I just often have difficulty figuring out whats considered a heavy copy. I suppose that would be things like.... sound objects, textures, stuff like that.

42
General / Re: References returning null values?
« on: November 02, 2012, 08:29:20 pm »
Functions are declared like this:
void doShitWithVector(const sf::Vector2f& vector);
sf::Vector2f calculateShitVector();
not like this:
void doShitWithVector(sf::Vector2f vector);//waste of memory passingvector by value
sf::Vector2f& calculateShitVector();//cant return reference to temporary vector from inside fucntion scope

But I'm not accepting any vectors in my functions. In fact.... I'm not accepting any input to them. They only create and return a vector.......

43
General / Re: References returning null values?
« on: November 02, 2012, 08:22:08 pm »
TAKE vector in SFML take const references or references

???

Not sure what you are talking about there...

This is the code I came up with.... am I right?
sf::Vector2u& EngineWindow::GetCenter()
{
        sf::Vector2u WindowCenter;

        sf::Vector2u FullSize;

        FullSize = this->getSize();

        WindowCenter.x = FullSize.x/2;
        WindowCenter.y = FullSize.y/2;

        return WindowCenter;
}
 

44
General / Re: References returning null values?
« on: November 02, 2012, 08:15:52 pm »
Does it really? Should cause access violation or stack corruption. It's also (possibly) leaking memory. Why can't you just return sf::Vector? There is no reason not to return sf::Vector or if you really need array : std::vector(which is unleaky, self resizing array).

Yep it somehow works. XD

I'll just use a sf::vector. Should I just return a copy then since its returning data to an outside class and get rid of the pointers?

45
General / Re: References returning null values?
« on: November 02, 2012, 07:56:44 pm »

Hey I was just wondering, whats your input on this?

int* EngineWindow::GetCenter()
{
        int *WindowCenter = new int[1]; //[0=X,1=Y]

        sf::Vector2u FullSize;

        FullSize = this->getSize();

        WindowCenter[0] = FullSize.x/2;
        WindowCenter[1] = FullSize.y/2;

        return WindowCenter;
}
 

I remember you saying not to use *new* but it does work with it, I just don't have a clue about how to delete it. It does work without error though. It returns a int Array.

Pages: 1 2 [3] 4 5 ... 10
anything