|
Dren posted:I haven't bothered to check but would using the non-template overload allow for use of the virtual keyword if f is a class method? Yes. The big gotcha with function template specializations is template argument deduction picking a slightly different specialization. If you have a function template template <class T> void foo(T&&);, and you wanted to specialize the behavior when the user passes an int, you might have to specialize at T=int for foo(0) and foo(returnsAnInt()), T=int & for foo(myCount), and T=const int & for foo(myForwardedArg) for foo(myGlobalConstant) or foo(myArg) from some other template function that took a const U &. But this is really a problem with all approaches: for example, you can't usefully add an overload that takes a pointer to a class that has subclasses, because template argument deduction will always generate a more precise match. That's why best practice is just not to overload function templates unless you put complicated SFINAE guards on them.
|
![]() |
|
![]()
|
# ? Jun 23, 2024 22:45 |
|
rjmccall posted:Yes. Great answer, thanks.
|
![]() |
|
Recently I've been having trouble debugging with Visual Studio 2013. I'll be going along, when all of a sudden after I either step over or try to expand a variable in the variables pane, the pane goes entirely blank (grey, in my case). Once this happens, I can't see any variables any more. As far as I can tell, it's time-related, happening at around five minutes. A month ago I was able to debug a program with much larger variables for quite a bit longer. I've tried rebooting my computer and only running VS, but it still happened. Any ideas what's going on?
|
![]() |
|
I've never heard of that, but I've got my own little collection of VS bugs and oddities that I'm pretty sure are caused by an extension. Do you have any installed yourself?
|
![]() |
|
Yeah, Devart code compare, C++ refactoring, image watch (for OpenCV images), and one from a class I TA-ed for. I uninstalled them, and I'll see what happens now. Edit: nope, still experiencing the problem. I guess I'll take it to their forums. hooah fucked around with this message at 16:01 on Mar 4, 2015 |
![]() |
|
You sure you're not debugging a release/optimized build?
|
![]() |
|
omeg posted:You sure you're not debugging a release/optimized build? Not that I'm aware of. At least, I didn't change any default settings since creating the project.
|
![]() |
|
Why doesn't VS 2013 have magic statics? ![]() Here's a nickel, kid...
|
![]() |
|
I'm not sure this is entirely the right thread but here goes. I'm using Qt for an application and I'm experiencing a problem similar to this one http://stackoverflow.com/questions/17175398/deployed-qt5-application-doesnt-print-or-show-print-dialog I'm using a QPrintPreviewDialog during the printing process. When I launch the dialog from the IDE (Qt Creator), clicking "print" launches the correct QPrintDialog and I am able to print the file I'm generating. However, when I deploy the program elsewhere clicking the same print button in the QPrintPreviewDialog only opens an "Export to PDF" save dialog. The part I'm stuck on is the debugging step mentioned in the Stack Overflow question. I can't seem to enable QT_DEBUG_PLUGIN properly. Does anyone know how to do this?
|
![]() |
|
Spatial posted:Why doesn't VS 2013 have magic statics? It does if you install the 2013 November CTP (or a later one).
|
![]() |
|
I just ran into a strange thing - it seems that C++ code:
C++ code:
C++ code:
hooah fucked around with this message at 01:24 on Mar 8, 2015 |
![]() |
|
That should work. Post a complete example.
|
![]() |
|
C++ code:
quote:Error 2 error C2677: binary '+=' : no global operator found which takes type 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' (or there is no acceptable conversion) On a different note, same project: I have a main.cpp and Chart.h, Chart.cpp, State.h, State.cpp. I guess I've been spoiled by Visual Studio, because trying to compile my project on the school's Unix server is an exercise in frustration. My includes (ignoring library files) are like so: C++ code:
C++ code:
C++ code:
C++ code:
|
![]() |
|
hooah posted:
It's complaining about C++ code:
C++ code:
Subjunctive fucked around with this message at 02:13 on Mar 8, 2015 |
![]() |
|
What do you expect the expression " [" += final.GetProduction().first to do?
|
![]() |
|
Subjunctive posted:It's complaining about Oh, sure, that makes sense. I was temporarily doing strings instead of ostrinstreams so I could check the contents as the result was being built up, so I just quickly changed all the << to += and expected it to work without thinking about it first.
|
![]() |
Crossposting from the Game Dev thread, since this is probably more of a C++ issue. I have a problem with compiling GLFW with my project in Windows with MinGW. The issue seems to be that when compiling GLFW it tries to do so with X11 headers, which, naturally, aren't available on Windows. I assume there's some flag or system variable I haven't set somewhere that I'm supposed to, but I can't figure out what the problem is. This is the error message I get (I get multiple, but they all refer to the same missing header): code:
Everything compiles fine under Unix. Does anyone know what's going on here?
|
|
![]() |
You're not defining the right configuration values. Look at this excerpt from glfw/src/internal.h: C++ code:
nielsm fucked around with this message at 10:48 on Mar 8, 2015 |
|
![]() |
Thanks, using a fresh download of GLFW did the trick. I'd done a simple git pull of what I'd used on my Linux machine, and I guess the GLFW cmakelist didn't know to reconfigure, so I added it to my ignore list. Of course, now SOIL is acting up for some reason. Same cmakelist as before, but for some reason it won't link the libSOIL.a because it can't recognise -lSOIL. code:
E: And of course GLM gives issues as well. Who knew cross-compatibility was such a pain. Joda fucked around with this message at 04:33 on Mar 9, 2015 |
|
![]() |
|
Can someone help me with a minor part of an end-of-term project I've been working on? I need to generate an object, aStudent, of class Student (below). Then, I need to populate it with id and gpa, and the bool statements. I get the bools from a return of one of my functions. The id and gpa I get from user input in main. I can't figure out the exact syntax for creating the new student object though, and populating it with the inputs from the user. C++ code:
PRADA SLUT fucked around with this message at 02:04 on Mar 14, 2015 |
![]() |
|
Hmm, it sounds like you might be more familiar with Java. Well, C++ is a bit different. When you are dynamically allocating memory, you are working with a memory address - a pointer, denoted by the * operator. So, to use your object, you would do this: code:
code:
Evil_Greven fucked around with this message at 01:28 on Mar 14, 2015 |
![]() |
|
Your Student constructor should probably be taking a const std::string& instead of a const char[]. C arrays are evil.
|
![]() |
|
C++ code:
edit: This is in main, the constructor is outside main. Does the constructor need to be in main or something? PRADA SLUT fucked around with this message at 02:08 on Mar 14, 2015 |
![]() |
|
Can you post all of the code (or at least the Student class and main, with the irrelevant parts elided)? It's hard to help when we don't know the types of name and gpa for example.
|
![]() |
|
name and gpa are just variable names I used in the example code above for him. The former should be id, I guess.PRADA SLUT posted:Both of these me there's no matching constructor for initialization of "Student", and a subwarning that the parentheses are disambiguated as a function declaration? C++ code:
(edit: old habits die hard, I guess - void main isn't C++ standard) Evil_Greven fucked around with this message at 02:36 on Mar 14, 2015 |
![]() |
|
Deus Rex posted:Can you post all of the code (or at least the Student class and main, with the irrelevant parts elided)? It's hard to help when we don't know the types of name and gpa for example. id and gpa are the private part of the class C++ code:
- Program generates Student with some arbitrary ID and GPA, using the Student class - User inputs another ID and GPA, program makes another Student with those properties. - Functions compare the ID and GPA of the user-inputted Student, with the Student the program generated - The user sees true or false to whether or not the ID or GPA of the entered Student are less than the generated Student PRADA SLUT fucked around with this message at 02:29 on Mar 14, 2015 |
![]() |
|
If this is a direct (albeit trimmed) code c&p, you don't seem to have built your constructor - only the function declaration for it. Assuming this is the case, that would explain your error. You can fake it out with the { } inline to prototype it, but if there is no function body... the function declaration is meaningless and the function itself doesn't actually exist to the compiler.
|
![]() |
|
Hmm? The inline { } should make it an empty inlined function, no?
|
![]() |
|
Subjunctive posted:Hmm? The inline { } should make it an empty inlined function, no? If it were there, yes.
|
![]() |
|
Oh, I mixed up Evil_Greven's for the actual example.
|
![]() |
|
That's the entirety of the code, minus some headers and a minor algorithm inside the functions to determine if they should return true or false. What would my constructor be then? Would I make a general one then use it to make a new Student? code:
Essentially a new Student will always be aStudent("a", 3.1), unless a pointer is used and overwrites the defaults with the values in quotes? When I need to call the function for comparison and output (returns true/false), do I just call bool Student::isLessThanByGpa(const Student& aStudent); in main? PRADA SLUT fucked around with this message at 06:45 on Mar 14, 2015 |
![]() |
|
Uhhh... okay hold on, I think we need to go over a few things. Those are not constructors. Right now, the constructor for Student that these statements are trying to use does not exist, so it's causing an error. Classes have members. Some of these members are functions. A few of those functions are special - constructors and destructors. These functions are called when an instance of the class is created or destroyed. There can even be multiple constructors (different parameters, for example), but only one destructor. You do not have a destructor defined for your class, but you do have a function declaration for a constructor: C++ code:
C++ code:
Evil_Greven fucked around with this message at 07:00 on Mar 14, 2015 |
![]() |
|
Oh poo poo, I'm sorry, I forgot to paste a bit of code in. Adding that line above gave me a redefinition error and I realized I omitted it accidentally in the post.C++ code:
edit: So we've got the definition, I'm just unsure of how to call the functions which are comparing the ID and GPA? PRADA SLUT fucked around with this message at 07:06 on Mar 14, 2015 |
![]() |
PRADA SLUT posted:
Those are two different ways to initialise an object of type Student, and are, as far as I can tell, only meant to illustrate that. They have no inherent relationship. The first allocates a Student on the stack (In simple terms, the part of your memory pool that has a fixed size,) while the other allocates a Student on the heap (the part of your memory that is dynamically allocated) and gives you a pointer to that object. They both use the same constructor, the only difference is where they are in memory and how you treat them when you call member functions and such. A constructor is, again in simple terms, a function that you can call to initialise an object with the values you want, and you need to write this constructor yourself like you would any other function, and set the values you want in there. I.e. you define it like you would any other member function except it doesn't have a return value. When you've done this you can call it to initialise a new Student object. For instance: C++ code:
PRADA SLUT posted:When I need to call the function for comparison and output (returns true/false), do I just call bool Student::isLessThanByGpa(const Student& aStudent); in main? When you want to call a member function you just write objectIdentifier.memberFunction(arguments). If it has return value you can assign it to something with the = operator (i.e. bool returned = objectIdentifier.memberFunction(arguments)). So, for instance, if you wanted to compare the two students from the earlier quote by GPA you would write something like bool aLessThanB = aStudent.isLessThanByGpa(*(pStudent)); I don't know if you're familiar with pointers, but since pStudent is a pointer in the former example it is necessary here to dereference. If pStudent had been allocated on the stack it would be bool aLessThanB = aStudent.isLessThanByGpa(pStudent); E: Come to think of it I've never had to dereference something like that (i.e. *(pStudent)) so I'm not sure if it'd work. Joda fucked around with this message at 07:17 on Mar 14, 2015 |
|
![]() |
|
I was confused because in the comparison functions, it had Student::isLessThanByGpa(const Student& aStudent), which looks like an awkward definition and CPP was thinking I was trying to redefine it instead of call it. I didn't think to do bool aLessThanB = ...C++ code:
|
![]() |
Yeah I actually fixed that. & returns a pointer * should dereference. Those two operators always gently caress me over.
|
|
![]() |
|
Just got that too, looks like everything is in order now.
|
![]() |
|
Another way of using those two particular variables would be:C++ code:
C++ code:
Evil_Greven fucked around with this message at 07:44 on Mar 14, 2015 |
![]() |
|
Evil_Greven posted:
![]()
|
![]() |
|
![]()
|
# ? Jun 23, 2024 22:45 |
|
PRADA SLUT posted:
The first line declares a local variable of type Student with automatic storage duration that is initialized with direct initialization. Direct initialization means the compiler will choose one of Student's constructors based on the types of the arguments you've provided inside the parenthesis and initialize the object by calling that constructor with the provided arguments. Unless you haven't mentioned some other constructor you've written for Student, your compiler will select the constructor you described earlier. Automatic storage duration just means that memory is allocated for the object when the program enters the start of the enclosing code block and deallocated for the object when the program exits the enclosing code block. This often means the object is allocated on the stack. The first line doesn't call a default constructor. A default constructor is one that can be called without any arguments; usually this just means its signature has an empty argument list. A class can often have an implicitly declared default constructor that the compiler will write unless you ask it not to. A line like Student defaultStudent; would call a default constructor, if the Student class has one, via default initialization. The second line does indeed declare a variable of type pointer to Student, but it doesn't point to aStudent. Could you just briefly explain why you think it points to aStudent? Evil_Greven posted:
This writes past the end of the array if the user supplies an input longer than MAX_CHAR - 1 characters. inputId will also be an invalid C string in this case which will probably eventually result in more undefined behavior (many functions expect a pointer to char or char array argument to be a C string!). By the way, that's why I suggested using std::string instead of a char array. C arrays are dangerous even in the hands of skilled and experienced programmers. Novice C++ programmers shouldn't be encouraged to use them, especially when there are strictly superior alternatives in the standard library like std::vector and std::string and even std::array.
|
![]() |