Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 08 Aug 2000
Offline Last Active Today, 08:43 AM

#5260289 How does this "pop_front()" implementation work?

Posted by BitMaster on 03 November 2015 - 05:43 AM

The move assignment in C++ is basically like the copy assignment, the key difference being that the moved object is left in an "will not be used again" state.

That is not true in this context. Standard library constructs guarantee (unless explicitly stated otherwise and I still can't say any class that does) that they are in 'unspecified but valid' state. You are explicitly allowed to do any operations on them which do not have preconditions. The standard also requires that any objects you put into its container stick to the same rule.

Edit: maybe some examples are useful:
std::vector<MyData> data = { ... };
somethingElse = std::move(data);
// data is now in an unspecified but valid state
std::cout << data.size() << "\n"; // <-- this is never a problem although we don't know what will be printed
std::cout << data.front() << "\n"; // <-- this is an ERROR. data can be empty in which case we violate the precondition of front()
data.clear(); // from here on we know data is empty
data.push_back(...); // now we know there is one element in there
std::cout << data.front() << "\n"; // this is no problem now

#5260270 Problem with OpenGL error

Posted by BitMaster on 03 November 2015 - 01:28 AM

Are you absolutely certain you are correctly checking the compile status of both shaders? The code you posted does not do any checks on the shaders and I cannot think of any other reason for the linker to cop out with such an error message. You should also verify none of the shader objects you attach are 0 for some reason or you deleted them too early.

#5260076 Problem with OpenGL error

Posted by BitMaster on 02 November 2015 - 02:10 AM

Are you checking whether the individual shaders have compiled correctly? Note you can retrieve a verbose error message from the driver to diagnose any problem here.

Are you checking whether linking the shaders into a program worked correctly? Note you can retrieve a verbose error message from the driver to diagnose any problem here.

Edit: And while I'm not sure what the standard says in newer version you should definitely try to write to gl_Position as your last action in the vertex shader.

#5259753 Derived Class Constructor from DLL

Posted by BitMaster on 30 October 2015 - 09:30 AM

This won't work that easily. Take a look at this. There are other ways to deal with the issues involved but especially if classes are involved this is probably closest to what you need.

Edit: I'd also like to point out that working with DLLs, especially if C++ is involved, has a lot of gotchas and restrictions. I would not do it unless I had a very good reason to do it.

#5259591 NonCopyable everywhere ?

Posted by BitMaster on 29 October 2015 - 10:30 AM

Security problem? No, it's just an API usability problem.

Not completely. If you just copy things around without any thought you can quickly come into a situation where your ownership is completely messed up and you double-delete or access deleted (or worse, already reallocated) memory. That's a crash problem to start with and can end up being a security problem when confronted with a determined attacker.

#5259555 Sign safer on this way ?

Posted by BitMaster on 29 October 2015 - 07:22 AM

Venturing off-ttopic, is there a reason to have three results? Often it's simpler to say that zero is positive by convention.

As someone with a mathematical background I would find that extremely vexing and force me to curse the author for at least twenty minutes. If you call it like the popular function then let it do what the popular function does. If you want something different, have the courtesy to call it differently.

#5259393 Jim. Adams's book

Posted by BitMaster on 28 October 2015 - 03:43 AM

Googling for 'WSACleanup' immediately leads to this page which says the function is defined in 'Ws2_32.lib' which you apparently do not link. Fix that, then apply the same procedure to whatever errors remain.

#5259266 Unresolved Externals problem... C++ / SDL

Posted by BitMaster on 27 October 2015 - 07:51 AM

I'm not too familiar with SDL but from what I remember SDL requires you to have an alternative SDL_main entry function. Check their documentation and example for details.

#5258636 When using C++ and including d3d11.lib, do you not use the windows registry a...

Posted by BitMaster on 23 October 2015 - 03:13 AM

You don't include a library like d3d11.lib. Include files (typically *.h) are included by the compiler, libraries are linked by the linker. Those are very different steps during the build process happening by different means for a different purpose.

I don't know what happens in D3D11CreateDevice and similar functions but I would expect them to be small stubs which query the correct interfaces from the OS via COM. To my knowledge DirectX 11 is part of the OS, so you will never run into a missing DLL though the device creation might fail if the graphics card driver present does not offer sufficient support.

#5258246 "No match for call to" error, help please

Posted by BitMaster on 21 October 2015 - 12:29 AM

[...] That's why make_shared is preferred, [...]

Did you mean to say 'make_unique'?


#5258115 Confusion with smart pointers

Posted by BitMaster on 20 October 2015 - 08:46 AM

While it is true that a moved-from type does not need to be anything but destructible, types in the standard library (including std::unique_ptr) promise more unless explicitly stated otherwise (right now I could not name a type that does). I'm just going to point over to a relevant StackOverflow topic which also quotes the relevant parts of the standard. Also note that any types you want to use with the standard library (for example inside a container like std::vector) must fulfill that promise too.

Edit: That explicitly means that you are allowed to call std::unique_ptr::get() and compare the std::unique_ptr with nullptr or other pointers.

#5258077 C# Float text format in other countries

Posted by BitMaster on 20 October 2015 - 05:40 AM

Why do you not want to output values in a format that people expect to see in different countries? That is the whole point of the regional formatting in the first place, it means numbers and dates are rendered as people are used to seeing.
As long as you use the culture setting for the machine the read/write in the different formats will be as the current regional settings are configured. 
Do your users a favour and show them values in the format they expect smile.png

As someone who sits in a place where the user-expected output is different from the C locale: functions or whole programs which think they need to stick to some locale setting they detected somewhere are highly annoying and the cause of extremely frustrating problems (up to the point of utter uselessness because floating point numbers have ',' as the decimal separator and use ',' to separate numbers).
Sure, if you need to present a number to the home-and-garden end user, you probably want a localized output. But I have found that for non-trivial programs that is in the minority compared to what else regarding textual input/output you need and in some programming languages getting clean, non-regional text in- and output can be quite a drag.

#5257945 Confusion with smart pointers

Posted by BitMaster on 19 October 2015 - 01:25 PM

Calling a member function of a null-pointer is undefined behavior. You might get an error. You might get something that looks like a working program. You might get something that looks like a working program but subtly corrupts memory leading to a crash down the road with no obvious connection to the cause.

For most compilers you can call member functions on a null-pointer provided certain requirements are met (not a virtual function, does not access any member data). It's still a horribly idea. It's still undefined behavior. It could still break the next time a new compiler version comes out or you change any compiler settings.

#5257871 Assign different functions to different structs in std::vector<>

Posted by BitMaster on 19 October 2015 - 03:26 AM

The same reason as why you needed the _1 for the bind. You create a lambda taking no parameter and assign it to something expecting an int-argument.

LayerMenu.Items[3+i].Items[0].SpecialMenuOnClick = [this](int index) { this->SelectLayer(index); };

#5257859 Adding some GUI to OpenGL

Posted by BitMaster on 19 October 2015 - 01:27 AM

In the interest of satisfying my own personal demons, the framework you are talking about is called 'Qt', not 'QT'.