|
Does anyone actually use pointer-to-member-functions (outside of the safe bool idiom)? I thought the wonky syntax and the existence of templates and virtual functions kept most people away.
|
# ? Oct 21, 2011 23:53 |
|
|
# ? Jun 8, 2024 12:13 |
|
tractor fanatic posted:Does anyone actually use pointer-to-member-functions (outside of the safe bool idiom)? I thought the wonky syntax and the existence of templates and virtual functions kept most people away. Well, not all code is appropriate or possible to template, and member function pointers are more lightweight than std::function. On the other hand, normal function pointers are even more lightweight, and std::function is a lot more flexible, so member function pointers only fill the very specific niche of wanting to do virtual dispatch without the extra overhead of std::function.
|
# ? Oct 22, 2011 00:09 |
|
I hope it is okay if I link to the stackoverflow.com page for my question. It's basically about how I can't figure out setting up CEGUI in Visual Studio 2010 without getting an error or another. The reason I can't get it working is lack of experience.. well, the link explains it: http://stackoverflow.com/questions/7857011/how-do-i-get-cegui-0-7-5-compiling-and-running-with-sfml-2-0-on-vs2010-c I guess it is easier for me to keep track of the answers in there as well.
|
# ? Oct 22, 2011 03:29 |
|
I don't know anything about CEGui, but I might be able to help if you post your compiler errors.
|
# ? Oct 22, 2011 03:31 |
|
Are you getting the errors at link time? Open up the project settings (Project -> Properties) and see if there is anything CEGUI related in VC++ Directories, C/C++ Additional Include Directories, or Linker Additional Dependencies.
|
# ? Oct 22, 2011 04:01 |
|
tractor fanatic posted:Does anyone actually use pointer-to-member-functions (outside of the safe bool idiom)? I thought the wonky syntax and the existence of templates and virtual functions kept most people away. Ever do this? code:
|
# ? Oct 22, 2011 04:32 |
|
TasteMyHouse posted:I don't know anything about CEGui, but I might be able to help if you post your compiler errors. I'm spent for today heading to bed, but I would like to take you up on your offer tomorrow. I'll post my errors then. Thanks!
|
# ? Oct 22, 2011 04:40 |
|
haha what, okay. How long would it take you to post your errors before going to bed though?
|
# ? Oct 22, 2011 04:49 |
|
Captain Cappy posted:Are you getting the errors at link time? I have included what I think I need in the VC++ Directories, C/C++ Additional Include Directories, or Linker Additional Dependencies. Now I'm getting new errors though: In debug configuration: (The weird thing about this one is that "c:\cegui-0.7.5\cegui\include\CEGUISingleton.h" isn't the directory I have specified anywhere. CEGUI is located in "c:\libs\CEGUI-SDK-0.7.5-vc10\" In release configuration: TasteMyHouse posted:haha what, okay. How long would it take you to post your errors before going to bed though? Edit: It's not like I prefer CEGUI over something else, I just need a GUI for my SFML C++ 2d game. CEGUI was just the system that seemed to cater to game development more directly than other options. It seems that all GUI systems I find are abandoned by their developers or at the very least poorly documented. I see the recommended GUIs in the OP but I don't know which to choose when I'm doing a game.. Abrahamsen fucked around with this message at 12:57 on Oct 22, 2011 |
# ? Oct 22, 2011 12:49 |
|
Abrahamsen posted:I have included what I think I need in the VC++ Directories, C/C++ Additional Include Directories, or Linker Additional Dependencies. Is this a DLL that gets included with the project or is it actually compiled on your machine? This would happen if a debug DLL was linked to the project - the path the assert failure would show would be where the source code was on the machine where it was originally compiled (I'm inferring directory structure of lib directory includes DLLS).
|
# ? Oct 22, 2011 15:34 |
|
I have a little useless C++ program that I am writing to explore objects, classes, and pointers. Currently I am trying to modify my (previously working) "Car" class so that it has an overloaded == operator with which to compare two Car objects for equality with respect to their 5 private member variable ("properties"). I am currently getting a compilation error which I assume has to do with pointers. I have no idea whats going on and could really use some help. I try to read resources/text books but they just don't explain the concepts well for me. Here is the compilation error: (VS 2010): code:
Here is the header file: code:
code:
Kosani fucked around with this message at 18:28 on Oct 22, 2011 |
# ? Oct 22, 2011 18:23 |
|
The problem is that your compare functions are 'const' (ie. explicitly do not modify their 'this'), and all your 'getSomething' functions are not const. Since you call these not const functions from within the const function, the compiler is concerned that the const function might be trying to modify things. Solution - make your get functions const. string getMake() const; and add a const in the same place for the function definition. (Probably also "compareFuelEff" should be const, since it's not going to be modifying anything. It should also take a const Car& rather than a Car as a parameter, since otherwise a whole new Car is copied into that function.) roomforthetuna fucked around with this message at 18:38 on Oct 22, 2011 |
# ? Oct 22, 2011 18:35 |
|
roomforthetuna posted:The problem is that your compare functions are 'const' (ie. explicitly do not modify their 'this'), and all your 'getSomething' functions are not const. Since you call these not const functions from within the const function, the compiler is concerned that the const function might be trying to modify things. Thank you. Your solution enabled it to compile. Is it good coding to just make everything that doesn't modify it's 'this' into a const? I thought I remembered reading that but I'm not sure why.
|
# ? Oct 22, 2011 18:51 |
|
hieronymus posted:Is this a DLL that gets included with the project or is it actually compiled on your machine? This would happen if a debug DLL was linked to the project - the path the assert failure would show would be where the source code was on the machine where it was originally compiled (I'm inferring directory structure of lib directory includes DLLS). I got the DLL from http://www.cegui.org.uk/wiki/index.php/CEGUI_Downloads_0.7.5 - under CEGUI 0.7.5 Binary Downloads for Microsoft Visual C++ 2010. I figured that I wouldn't have to do anything to the DLLs other than link them.
|
# ? Oct 22, 2011 19:03 |
|
Kosani posted:Thank you. Your solution enabled it to compile. Is it good coding to just make everything that doesn't modify it's 'this' into a const? I thought I remembered reading that but I'm not sure why. Yes, because otherwise you will run into the problem you just ran into.
|
# ? Oct 22, 2011 19:05 |
|
Kosani posted:Thank you. Your solution enabled it to compile. Is it good coding to just make everything that doesn't modify it's 'this' into a const? I thought I remembered reading that but I'm not sure why. Technically you can avoid your compilation problem by making nothing const, but using const properly protects you from some mistakes.
|
# ? Oct 22, 2011 19:13 |
|
roomforthetuna posted:Technically you can avoid your compilation problem by making nothing const, but using const properly protects you from some mistakes. The other problem with avoiding const is you can't use temporaries.
|
# ? Oct 22, 2011 20:25 |
|
tractor fanatic posted:The other problem with avoiding const is you can't use temporaries. Or third-party libraries that use const.
|
# ? Oct 22, 2011 21:50 |
|
I'm porting some windows code over to OSX. Parts of the code were using windows-specific typedefs for some at some places (UINT for unsigned int, LONGLONG for long long, HRESULT, etc). Is there some header file that I can include that will allow me to ameliorate this easily or should I do some manual typedefs instead?
|
# ? Oct 23, 2011 03:35 |
|
Anywhere you write HRESULT almost certainly needs to be properly ported. You could make your own typedefs for UINT and LONGLONG, and it would probably be faster than finding someone else who's done so, but be aware that the most important OSX architecture these days is 64-bit; you might be a lot happier using uint32_t and int64_t and the like, which should also work fine on Windows.
|
# ? Oct 23, 2011 05:32 |
|
By the way, if stdint.h isn't available on your system (e.g. Visual Studio <2010) pstdint.h is a good portable implementation.
|
# ? Oct 23, 2011 05:43 |
|
rjmccall posted:Anywhere you write HRESULT almost certainly needs to be properly ported. You could make your own typedefs for UINT and LONGLONG, and it would probably be faster than finding someone else who's done so, but be aware that the most important OSX architecture these days is 64-bit; you might be a lot happier using uint32_t and int64_t and the like, which should also work fine on Windows. This is some code that interfaces with the MSR Kinect API (that looks like Win32 on the C++ side and of course uses HRs). I plan to have the preprocessor take out the offending bits and pieces of code based on #defines. So uint32_t and int64_t safely assign to UINT and LONGLONG? Also, why does Xcode complain when I try to #typedef unsigned int UINT?
|
# ? Oct 23, 2011 05:45 |
|
shodanjr_gr posted:Also, why does Xcode complain when I try to #typedef unsigned int UINT? Because the '#' is for preprocessor directives. Don't prefix the typedef keyword with '#'.
|
# ? Oct 23, 2011 05:59 |
|
Whooooore! Why won't you work?! I'm failing at overloading the iostream << operator... someone tell me how I'm being retarded so I can hopefully be less retarded in the future. Doing this: FractionClass.h code:
1>...\fractionclass.h(36): error C2143: syntax error : missing ';' before '&' 1>...\fractionclass.h(36): error C2433: 'ostream' : 'friend' not permitted on data declarations 1>...\fractionclass.h(36): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>...\fractionclass.h(36): error C2061: syntax error : identifier 'ostream' 1>...\fractionclass.h(36): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>...\fractionclass.h(36): error C2805: binary 'operator <<' has too few parameters
|
# ? Oct 23, 2011 06:08 |
|
It is a namespace issue. Put std:: before ostream and the errors will go away.
|
# ? Oct 23, 2011 06:12 |
|
delta534 posted:It is a namespace issue. Put std:: before ostream and the errors will go away. I could kiss you right now. I forgot to add using namespace std when I flipped it into it's own .h file.
|
# ? Oct 23, 2011 06:16 |
|
Souper posted:I could kiss you right now. I forgot to add using namespace std when I flipped it into it's own .h file. You should indeed forget this. Reference the namespace directly in the header and only put using statements in source files. Otherwise you're bound to get some very strange namespace collisions sooner or later.
|
# ? Oct 23, 2011 06:36 |
|
Mmm, that makes sense. Thank you for the heads-up. The book I'm working out of keeps all it's examples in one file. Not really workable in the real world, so I'm deliberating breaking things out into their own files to learn via trial and error. Does anyone know of.. I dunno, an online idiot's guide to good form when making headers/ multiple file projects?
|
# ? Oct 23, 2011 06:50 |
|
MutantBlue posted:Because the '#' is for preprocessor directives. Don't prefix the typedef keyword with '#'. God I am a moron. Thanks....
|
# ? Oct 23, 2011 06:55 |
|
Souper posted:I could kiss you right now. I forgot to add using namespace std when I flipped it into it's own .h file. Do not put using namespace std; into a .h file! Then the entire std namespace will be imported into everything that includes that file without the knowledge of the person using that header. e: beaten oops TasteMyHouse fucked around with this message at 07:25 on Oct 23, 2011 |
# ? Oct 23, 2011 07:14 |
|
I'm trying to brush up on some coding, re-doing a maze solving program from college. I'm trying to read a maze file (just a text file with "X" for walls, "O" for end point, "I" for start point) into a pointer array, then I'll use a stack to find the solution. The problem is that I'm loving up the part where I write the individual characters of the maze into a char array. If I output the contents of the pointer array, only the last row has any characters in it. I figure I must be overwriting something in my array building for loop, I think the "array_ptr[i] = new char[mazeSize];" isn't doing quite what I think it is. But I can't think of another way to do it. code:
code:
|
# ? Oct 23, 2011 16:37 |
|
You've got your x and y confused in places, is the problem. You're making a new array-line every character instead of every line (your 'i' is a synonym of 'x'). Instead of array_ptr[ i] = new char[mazeSize]; inside that loop, you want array_ptr[y] = new char[mazeSize]; before the loop, and then when you're reading to it you want array_ptr[y][ i] rather than array_ptr[ i][y]. (Probably other related changes too, but hopefully that will get you going.)
|
# ? Oct 23, 2011 16:58 |
|
if the maze is square, you don't need to check what it's width it every iteration. Also, what is myCountMazeRow for? you never use it.
|
# ? Oct 23, 2011 18:15 |
|
What's the usual strategy for dealing with circular dependencies in inline functions that are in separate headers? i.e. Header A defines some types and some inline functions that depend on some structures in header B, but the reverse is also true.
|
# ? Oct 23, 2011 18:33 |
|
Well, it's kind of hackish but you can turn the functions into templates.
|
# ? Oct 23, 2011 18:53 |
|
OneEightHundred posted:What's the usual strategy for dealing with circular dependencies in inline functions that are in separate headers? I don't know what "usual" is, but this is what I do: code:
code:
You also don't need to write inline in both places, I'm just doing it here for clarity. Edit: I consider this to be better than introducing separate "implementation" headers since it reduces the number of files and makes it difficult to misuse.
|
# ? Oct 23, 2011 18:55 |
|
roomforthetuna posted:You've got your x and y confused in places, is the problem. You're making a new array-line every character instead of every line (your 'i' is a synonym of 'x'). Instead of array_ptr[ i] = new char[mazeSize]; inside that loop, you want array_ptr[y] = new char[mazeSize]; before the loop, and then when you're reading to it you want array_ptr[y][ i] rather than array_ptr[ i][y]. Thanks, I was convinced the problem was elsewhere, working now.
|
# ? Oct 23, 2011 21:51 |
|
I have a question about boost multithreading and variables. I have some threads looping on their own bools. When they go false, I exit the thread. I think sometimes this isn't working. What I've seen in the long past last time I dealt with this was that the value was getting cached, so one thread's true was another thread's false. What is there in boost's own stuff to eliminate this kind of problem. I assume there's something more robust than just declaring all the relevant stuff volatile, and I don't think mutexes are going to protect me from that. Wouldn't a mutex just ensure at one time only one thread is touching a representation of the variable?
|
# ? Oct 24, 2011 01:07 |
|
Rocko Bonaparte posted:I have some threads looping on their own bools. When they go false, I exit the thread. I think sometimes this isn't working. What I've seen in the long past last time I dealt with this was that the value was getting cached, so one thread's true was another thread's false. What is there in boost's own stuff to eliminate this kind of problem. I assume there's something more robust than just declaring all the relevant stuff volatile, and I don't think mutexes are going to protect me from that. Wouldn't a mutex just ensure at one time only one thread is touching a representation of the variable? Volatile may or may not be what you're looking for. What you need to understand is what volatile guarantees, and what it doesn't guarantee. Declaring a variable as volatile essentially means that all reads and writes to it actually go and touch that storage location, and it's guaranteed that those accesses won't be optimized away. It's also guaranteed that accesses to volatile variables won't be reordered with respect to each other. What volatile doesn't guarantee is ordering with respect to non-volatile accesses. In the common multithreading scenario, your shared data isn't volatile (because that's a significant performance hit in a lot of cases), but you're using some other variable to synchronize access. In that case, volatile isn't enough, because the compiler is allowed to move the access to shared data on to the wrong side of the volatile access. In your specific scenario, volatile may be sufficient, depending on what you're actually doing in these threads.
|
# ? Oct 24, 2011 01:48 |
|
|
# ? Jun 8, 2024 12:13 |
|
Interesting reading regarding threading, reordering, and the problems therein http://www.hpl.hp.com/techreports/2004/HPL-2004-209.html
|
# ? Oct 24, 2011 01:58 |