« first day (739 days earlier)      last day (2118 days later) » 

7:06 AM
Why can't I define same name const variable in different file? That should be fine.
//test.h
#pragma once
const int i = 5;
//main.cpp
#include "test.h"
const int i = 6;
int main()
{
	i;
}
Why do I get i redefinition error?
 
 
2 hours later…
Ron
8:38 AM
Something unclear to me about the std::future. The third bullet states: ...it can do so by modifying shared state (e.g. std::promise::set_value) that is linked to the creator's std::future..
I don't quite get the std::promise. If we have packaged_task, and async then why do we need the promise?
Particularly confusing is that third bullet. We already have functions returning std::future and we still need to utilize the std::promise? Or is it that we might utilize the promise::set_value feature. I don't understand the overhead. Or is it simply a feature that can be used.
It is also unclear to me if it launches a thread or only provides a facility to store a return value. Excuse the mountain of text.
 
 
1 hour later…
10:04 AM
315
Q: What is std::promise?

Kerrek SBI'm fairly familiar with C++11's std::thread, std::async and std::future components (e.g. see this answer), which are straight-forward. However, I cannot quite grasp what std::promise is, what it does and in which situations it is best used. The standard document itself doesn't contain a whole l...

Most people who do threading realize really quickly that, despite their intentions, things like promise and future are performance antipatterns. Almost always the correct solution is a producer consumer queue. Once a year a parallel prefix sum.
 
Ron
@Mikhail I see. Appreciate it.
 
 
2 hours later…
Ron
11:58 AM
Why is packaged task in this example accepting &fib rather than just fib?
Eeer, found it. My bad. Still looks a bit odd.
 
nwp
I don't see why you would even use a packaged_task here. What does that give you over a promise?
I know that you go from the other side and say "If I have a packaged_task, why do I need a promise", but you can do more things with promises than packaged_tasks. I think.
 
Ron
I see.
I thought I cover all the theory surrounding threading wrappers.
I was under the impression I should prefer the packaged task judging by this FAQ post.
 
nwp
12:19 PM
I understood you use packaged_task when you want to launch a thread. While this occasionally happens I have the "other thread, run this function and give me the return value" situation more often. Not sure if you can still use packaged_task for that.
 
Ron
Ah I see now. Thanks.
I guess then it doesn't get much simpler than auto f = std::async(...);?
I am still struggling to differentiate between a std::thread wrapper and functions returning std::future.
 
nwp
12:35 PM
If that is sufficient then it's probably as simple as it gets.
But then people want to have thread pools or want to pass a stream through the future or want future.then or ... and then you have to use something else.
 
Ron
I see.
 
nwp
Arguably you can make a new function that does return std::async(std::launch::async, ... because that's probably what you always want.
If only std::launch::async | std::launch::deferred did what it is supposed to.
 
Ron
I see. Appreciate it. Might take some time for me to grasp all this concurrency shebang.
 
 
1 hour later…
2:02 PM
hi there! does somebody know about programming openGL apps on macOS using xCode and gl-libs like glew/glfw? got problems with rendering :(
 
2:34 PM
@Rick it's not a different file the moment you did #include "test.h"
 
@Rick same compilation unit both to global scope....
 
 
2 hours later…
4:12 PM
@ArkadiyAfonin use qt, or a game engine
 
4:41 PM
Hi folks, does anyone have a hot second to give me a hand with a linker error I'm encountering? I did some reading on the site, but it hasn't helped me much.
 
No need to ask to ask, just ask
 
Oh, great.

So, I have a class declared in a header as so:

#pragma once

#include <GL\glew.h>
#include "renderer/RawModel.h"

class Renderer
{
public:
void prepare();
void render(RawModel raw_model);
};
I have both of those methods implemented (bodies left out, here's just the signatures)

#include "renderer/Renderer.h"

void Renderer::prepare()
void Renderer::render(RawModel raw_model)
But when I try to use the methods, I get a linker error claiming the functions aren't resolved.
My usage looks like this:

Renderer renderer;
// do some stuff in betwee...
renderer.render(quad_model);
I'm including the file for RawModel and Renderer in the class calling the function, so I'm not sure why this wouldn't work?

I checked the signatures to make sure it wasn't just a typo, and I don't see anything standing out. Am I misunderstanding what the error is trying to tell me?
 
How are you compiling?
 
Just through the standard "Local Windows Debugger" option in Visual Studio 2017.
Not sure what that uses behind the scenes, I mainly work in JVM based stuff, so I'm not super comfortable with the whole C++ toolchain yet.
 
What is the actual linker error? Can you paste that here?
 
4:48 PM
Sure, one second.
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "public: void __thiscall Renderer::prepare(void)" (?prepare@Renderer@@QAEXXZ) referenced in function _main
That's the first one, the other is basically the same thing for my call to the second function.
 
Okay
So you have a Renderer.h, Renderer.cpp, main.cpp. Do all of them show up in the project?
 
Checking
Main is there too, just cut it out accidentally.
 
Is this a cmake project, or a VS project?
 
VS, as far as I know. I haven't changed the default settings. Is there a way I can check?
 
Is there a CMakeLists.txt under the project?
 
4:55 PM
Negative, not that I see.

I don't think it's relevant, but I do use Nuget on the project to load some libraries like GLEW and GLFW since I haven't really taught myself how to manage these dependencies manually yet.
 
Yeah, that's not what's causing the error. If that was the problem, the unresolved external symbols would be from those libraries, not from Renderer
It looks like somehow, Renderer.cpp isn't getting compiled (or linked). At this point, I personally can't help you any more. I don't have enough experience with Visual Studio to just know how to check if the Renderer.cpp is getting compiled and linked in. I'd need to have access to the set up in person so I could work with it. Sorry :-(
 
I'm not quite skilled in interpreting these errors yet, what exactly is it telling me?

Basically, as I understand it, it just can't find the function with the signature it was expecting?
What is the ?prepare@Renderer@@QAEXXZ bit it's spitting out? A memory address or something?
 
From a compiler's point of view: in C++, you can declare functions, not just define functions. So if you write ReturnType someName(...);, whether it's a member function or not, the compiler trusts you and says, "Okay, there's going to be a definition for this function later." However, when "later" comes, the linker can't find a definition for the function, so it says there's an unresolved external symbol.
@Airhead I think that's a mangled name. Basically, since C++ has overloaded functions and classes, it has a way to mangle all that information into a mangled name which the linker works with
 
Hmm... how can one debug/avoid that?
 
1189
Q: What is an undefined reference/unresolved external symbol error and how do I fix it?

Luchian GrigoreWhat are undefined reference/unresolved external symbol errors? What are common causes and how to fix/prevent them? Feel free to edit/add your own.

 
5:03 PM
I've browsed that, but it's a lot of info to take in at once.

So if it is a mangled same, could it potentially be solved or at least verified by changing the name of the class?
 
No.
 
Oh, I reread your statement, I understand what you are saying now - you were referring to my additional question about the error message.
 
Yes
 
If you suspect it to be a visual studio issue, is it possible compile it with some other compiler from the terminal perhaps, without too much difficulty?
 
I don't think it's a Visual Studio issue, I think it's a project setup issue. Yes, you could compile it with some other compiler to help verify that, but unfortunately, that's not easy on Windows
 
5:10 PM
Is it worth grabbing a download of CYGWIN?
 
Personally, I don't think so. Odds are that there's something relying on VS specific behavior. What I'd do is study the project settings and see if anything seems wrong. Also note that individual files can have settings too, so I'd also check Renderer.cpp's settings.
What you are looking for is: Is Renderer.cpp getting compiled? Is that getting linked in?
 
Hmm... if it is potentially a file specific setting, I may try deleteing the file from the disk, creating a new file, and pasting the contents in.
 
Not a bad idea
The other thing is to ensure that the definitions actually match the declarations. I don't think the compiler lets you define a member function for which there's no declaration, but make sure that they match up, including the namespace. That's where most of my linker errors come from.
 
I've checked the signatures pretty well. Another telling sign is that when I go to the header file, and click "Go to definition", it takes me to the correct place.
 
Yeah
 
5:17 PM
And I'm not using namespaces in this project, maybe that could be a rememdy? Wrap everything in a dummy namespace?
I wouldn't think so.
I've read that these types of things can sometimes be related to includes being in the wrong order. Is this a possibility?
 
I don't think so. I don't think that include order affects the linker
 
Okay, just to eliminate file specific stuff, I've created a new header and new implementation file called TestLoader.h and TestLoader.cpp - same error
I've also right-clicked on TestRenderer.cpp and clicked compile, which I assume forces the specific file to compile? That succeeds according to VS. Still same error, though.
Solved it!
I hate microsoft a little more at the moment.
So, I have visual studio configured to show me the actual file structure on disk, you know, the way any sane person would do it. However, the default in visual studio uses something called "filters" instead of folders - filters don't correspond to a real folder on the disk. When you create a new file and stick it in a "filter", in reality it all just gets dumped into one big folder containing all of the source code for the project.

Like any sane human being, I immediately realized that was completely obnoxious and sought to get around it. There is a tiny little button in VS that allows you
Ugh
Thanks for all the help, Justin.
 
5:49 PM
Nice :) Glad you figured it out @Airhead
 
Why does every IDE try to push some obnoxious project management structure unique to them on you?
 
because compiling C++ is a nightmare
 
6:10 PM
Ain't that the truth - coming from the JVM toolchain, I feel like I'm in purgatory.
 
@Airhead I wouldn't call java any rose either
you have any number of toolchains there too
 
Oh, certainly not, it's a nightmare too, but at least it's a moderately standardized nightmare, lol.
Where's Ballmer to shout developers when you need him?
 
the only real hassle you have with java is the forced file structure with the packages and handling the class path
 
 
5 hours later…
11:43 PM
With Boost Spirit X3, is there a good way to ignore the attribute, but supply your own? In other words, how do I produce a known value whenever the parser succeeds? Here's a snippet to show what I'm talking about: wandbox.org/permlink/pyXXTC15k7zFUY0D
The more general case is taking an attribute and mapping that to some other value. In this particular case, my mapping is ignoring the original attribute and producing a constant value
 
Hey, does anyone know of an algorithm which, provided a finite, 2D area (perhaps represented as a 12x12 matrix), will randomly select non-overlapping rectangles and squares from that area within certain constraints (such as size of areas or distance between any two areas)?
 
for maze generation?
 
11:59 PM
Somewhat, yes. Imagine them like rooms.
 
@Justin I found my answer: x3::omit[parser] >> x3::attr(value): wandbox.org/permlink/4jjf1RZbErgAyYCl
 

« first day (739 days earlier)      last day (2118 days later) »