2,898 Posted Topics
Re: First [URL="http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.3"]read this[/URL], then [URL="http://www.parashift.com/c++-faq-lite/virtual-functions.html#faq-20.8"]this[/URL], and finally [URL="http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.5"]this[/URL]. I'm not sure I fully understand what you are trying to do (can you show some pseudo-code). If you are trying to simply re-use the code to do the initialization of the class, then, of course, a separate initialization method (function) would … | |
Re: Change the type of display_Desig at a pointer to char, char *. And with the single equal sign for assignment, it should fix the compilation error. For the rest, there at least two small things to change / add: 1. change the type of all those B_SAL, H_ALLOW... variables to … | |
Re: In this case, the struct is, IMO, totally appropriate. And NO, [URL="http://www.parashift.com/c++-faq-lite/classes-and-objects.html#faq-7.9"]there is no functional difference between classes and structs[/URL] except for the default access rights (private, public) which you shouldn't use anyways because it is better to be explicit about the access rights. In this case, the data inside … | |
Re: Here are a few facts: 1. If you hold a map of objects (not pointers) of the base class, then it's going to be objects of the base class, not a derived class, that's impossible without a very nasty hack (reinterpret cast on the object). DON'T DO THAT! 2. There … | |
Re: Ok, so the statement you are having an issue with is: [CODE]if(!head)[/CODE] Lets go by it step by step. First, the if-statement, of course, takes a boolean value (true or false) and executes the next statement if that boolean value is true. Then, the ! operator is the NOT boolean … | |
Re: >>I am using the modulo operator with a double when it can only be used with ints. Although you don't need it here, if you do need in the future, the modulo function for double is [URL="http://www.cplusplus.com/reference/clibrary/cmath/fmod/"]fmod()[/URL]. | |
Re: Simply make a MACRO to wrap the function call: [CODE] //in MyDebugUtilityFunctions.h void ReportError(int lineNumber,Wstring ErrorTitle,Wstring ErrorMessage) { ... report the error ... }; #define MY_DEBUG_ERROR_REPORT(X,Y) ReportError(__LINE__,X,Y) //say in the main.cpp, or anywhere else. int main() { ... MY_DEBUG_ERROR_REPORT("Fatal Error!","The main function crashed here!"); ... }; [/CODE] The MACRO will … | |
Re: Every floating-point representation like float, double, or even long double, will inherently have a round-off error. Usually, for these three types it is rounded-off around the 7, 16, and 20 significant digit (although long double may not be different from double, and the precisions can change per platform). So, even … | |
Re: I would recommend you switch to cmake instead, but to fix your makefile. Add the "$(pkg-config --cflags --libs cairo)" to CPPFLAGS, like this: [CODE] CPPFLAGS += $(pkg-config --cflags --libs cairo) [/CODE] I'm pretty sure that or a variation of it should do the job, but I'm not an expert on … | |
Re: @Fbody: you covered two good cases, but none are about the OP's question. If you have a nested class, then the this pointer, within a call to a member of the nested class, refers to an instance of the nested class (not its wrapper class). However, the nested class has … | |
Re: Just throwing in my grain of salt.... I'm mainly a Linux user so I may be biased. I find mingw (as I assume it is the same as the Linux gcc) to be much more helpful in general. It is easier to know that your are compiling and the error … | |
Re: Well you are stepping into the realm of const-correctness which is this idea that if you want to be rigorous, you should put const everywhere where a variable is constant or required to be constant. You are right that a lot of people (especially beginners) are frustrated at the const … | |
Re: Don't use the code from sundip, it is erroneous. In your original code, there is a memory leak because you loop again and reallocate the memory for a new array on top of the previous one. Since the destructor of all those Fuzzy objects don't get called, the n value … | |
Re: >>what is the int in operator++(int) It's just used to differentiate the two functions. It means nothing at all. | |
Re: [URL="http://www.parashift.com/c++-faq-lite/pointers-to-members.html"]This page[/URL] might help, but I'm sure it's the first you found in researching this issue. I know why the error happens. "this" and "this" are different. Let me explain. The this pointer you pass to the function is of type TitleScreen* but can be implicitly casted up to a … | |
Re: I see one big problem. You should not do anything complicated in the DLL entry point function. This is because there are certain intrinsic properties that make the DLL_entry somewhat different from a normal function call. These special things have to do with the OS being able to load the … | |
Re: I think, you have to make the pointer a private or protected member, because the compiler will say it is incomplete because it should be accessible to an outside part (like main()) which has no idea what the real declaration of myVector is. Since the VecPtr can be dereferenced in … | |
Re: The code you posted is a bit weird, what is C1dArray? Anyhow, simply put: [CODE] ... imgArray = new unsigned char *[size]; myStream.read(reinterpret_cast<char *> (imgArray),(fileSize)*sizeof(unsigned char)); //notice fileSize not size //set the nullterminating char, if you really need it (IMO you don't). imgArray[size-1] = 0; int* pArray = new int … | |
Re: There is no implementation for either of these methods: [CODE] void Mob::set_data(string name, int level, int given_xp, int given_gold, int attack, int defence, int max_hp, int max_mp, int max_tp, int attack_spd); void Mob::add_ability(Ability); [/CODE] | |
Re: You have to specify the correct include path in your own stuff too. This error is not in the FTGL library which compiled successfully. Once compiled, it no longer needs to find the includes for the .lib, but it needs to find the includes that you use in your code … | |
Re: C: forget it, it is possible of course, but I can comfortably say that people don't really make a conscious choice to program in C. Usually it is because either it is a special very low-level platform for which C is the only choice, or because its an old library … | |
Re: I know you solved the problem, but may I suggest a more elegant method IMO. This is a typical case where an interface class and multiple inheritance could do very well: [CODE] //Callback.h class IMouseClickCallback { public: virtual void MouseClickCallback() = 0; }; //Client.h class Client : public some_other_base_if_any, public … | |
Re: >>I'd also recommend putting all includes into the header file rather then the .cpp NO absolutely not, if we are talking about best practices in coding. OP: The way you did it is fine. You include as few headers as you can in your headers and include the headers you … | |
Re: Well, as a start, you need to split the number into each base 10 digit, for example: [CODE] std::vector<int> SplitDigits(int Number) { std::vector<int> result; while(Number > 0) { result.push_back(Number % 10); Number /= 10; }; return result; }; [/CODE] That's a start, now you go from there and figure out … | |
Re: The problem is that pTSL1_Commands->TSL1_ReadMemory32 is a "method" not a "function". The difference is that a method has the implicit "this" pointer to the object passed to it, while a function only has the parameters of its prototype declaration. So a function pointer, if you need to use one and … | |
Re: Well, there are several places to put it, depending on what you want. I am not an expert with VC++, so the names I give my not apply directly (they would apply directly to Borland C++Builder and VCL) but usually they correspond well. Usually there are callback functions, like OnClick() … | |
Re: I don't mean to interrupt, but usually when you want a really robust binary interface for a byte-stream. You don't cast, or stringify, or pack/pragma, or what give you. You implement a binbag with off-the-hook protection from cross-platform, cross-compiler, cross-compiling-option.. the whole shabang. Implement the binbag's interface on the model … | |
Re: Ton problème est que lorsque tu fais l'addition de plusieurs chaines de charactères, ses chaines sont converties en "String^" pour être additionner. Une fois additionné, tu as un String et non une chaines de charactère (char[] ou char*), et ils ne sont pas compatible implicitement. Donc, pour régler le problème, … | |
Re: Did you consider making a method instead? such as: [CODE] template <typename T> class node { public: T nodeValue; //data held by the node node<T> *next; //next node in the list //default contructor with no initial value node() : next(NULL) {} //constructor. initialize nodeValue and next node(const T& item, node<T> … | |
Re: The problem is that you need to have the same access right for the overwritten function in the derived class, otherwise, the compiler will call the public function first. So, simple correction: [CODE] class BaseClass { public: void setInputParameter() { inputParameter_ = inputParameter; } void computeFunction( const double& inputParameter ) … | |
Re: We don't just solve assigments here! You start it, get some code going, and post specific problems with the code you have. We have to see that you have been making a real effort to solve this problem by yourself. We only give help to cross the few hurdles you … | |
Re: that simple: floating point values on a computer always approximate the real value to some round-off error (about to the 7th significant digit for float and to the 20th significant digit for double). So the comparison i<=stop_temp is not going to work all the time because even when i is … | |
Re: NO, if only the return type differs, they cannot be overloaded (i.e. have the same name). C++ standard specifies that overloading is only for different parameters (their types or their number), not return types. So, to have different return types. You have a few options (in order of what's easier … | |
Re: >>does that mean that I need to overload the operator to work with my class? NO absolutely not. DO NOT OVERLOAD THE -> OPERATOR! The correct syntax in your case is: points[size].x | |
Re: You had some things the wrong way around: [CODE] subarray(int* Array, int start,int end) { typedef int* ptr; ptr sub; int count = end - start; //the sub-array's size is not "end", but "end - start". if (count <= 0) //check that you actually have a sub-array to create. return; … | |
Re: Dumping a thread like this is not nice, but while we are at it. For outputting, I like this better: [CODE] //in some basic header of your software. #ifndef DEBUG_VERBOSITY #define DEBUG_VERBOSITY 5 #endif #define DEBUG_NOTICE(X,Y) if(X <= DEBUG_VERBOSITY) std::cout << __FILE__ << ":" << __LINE__ << " " << … | |
Re: From my experience, this looks like a memory corruption problem. Maybe playing with valgrind can help you. Also, try outputting the pointer addresses you use. verify each dynamic memory allocation to make sure you never use an uninitialized pointer. Also check bounds on for-loops and stuff, make sure you are … | |
Re: @yup790: Try this code, and you can hand it in as is: [CODE] #include <iostream> #include <algorithm> #include <functional> using namespace std; const char hello_world[] = {0x49,0x20,0x61,0x6D,0x20,0x61,0x20,0x63,0x68,0x65,0x61,0x74,0x65,0x72,0x21,0x00}; struct printOutFunctionObject { void operator () (int) { cout << hello_world << endl; }; }; struct null_iterator { bool operator !=(const null_iterator& iter) … | |
Re: [URL="http://stackoverflow.com/questions/137038/how-do-you-get-assembler-output-from-c-c-source-in-gcc"]Read this[/URL]. | |
Re: MACROs are evil! Don't use them. From the looks of it, that you need is a look-up table. If you are restricted to C, from the looks of your code that is the case, then you can do this: [CODE] struct myKeyword { const char name[]; int ID; }; myKeyword … | |
Re: What about this: [CODE] class vec3f { private: GLfloat q[3]; public: GLfloat& x() { return q[0]; }; GLfloat& y() { return q[1]; }; GLfloat& z() { return q[2]; }; vec3f(){}; vec3f( GLfloat x, GLfloat y, GLfloat z ) { q[0] = x; q[1] = y; q[2] = z; } *operator … | |
Re: What Lusiphur said is true for freeing or deallocating memory. Most of the time, for small applications that don't run for very long and don't use any OS resources (like threads, external processes, internet connection sockets, etc.) it will work fine without explicitly freeing all allocated memory, but not good … | |
Re: Agreed. It is also good practice to play around with the example codes. For example if you are not sure why a particular line code is there or why the author does something in a particular way, you can just change it and see what happens. It's good to also … | |
Re: Well in the above, the "&function" syntax is a function pointer which you can Google for. And the "hooks" that you are talking about is, from what I understand of your explanation, what is commonly known as "callback functions" which is very heavily used, especially in C interfaced libraries (such … | |
Re: I see two things that could be happening that makes it compile without error in VC++: 1. VC++ might actually mangle the names differently according to return type, the standard allows it even though it really serves no purpose because overloaded return type are not supported, so who knows, maybe … | |
Re: Well, since your original code is so far off, and sfuo already posted a valid solution, let me just post a slightly better one that applies if you don't care about the print order at all: [CODE] void printAllFactors( int in ) { //start at 2 if you want it … | |
Re: You might have a dangling newline on the cin, so when you try getline it returns an empty line before you even have time to enter anything. Simple solution, replace the "cin >> answer;" part with: [CODE] cin.ignore(); //this will ignore any newlines that are on the input buffer but … | |
Re: [QUOTE]B=N*I*R*R/2[R*R+x+x]^3/2;[/QUOTE] Is not a valid C/C++ syntax. the ^ operator is not for power (it's binary XOR which I doubt is what you intended). C/C++ is not matlab or mathematica or a hand calculator. If the function is, as I understand it: B = (N * I * R * … | |
Re: I think there is no need to dig up a place in the C++ standard where it says something like: "a class Foo derived from class Bar cannot access the protected members of Bar from another object of type Bar or any other of its derived class, including Foo." Because … | |
Re: Well MSDN says this: [QUOTE]The classes in <strstream> are deprecated. Consider using the classes in <sstream> instead.[/QUOTE] And [url]www.cplusplus.com[/url] has no mention of strstream at all, it seems to have vanished from their standard library reference documents. It appears also that strstream uses char arrays in the underlying implementation while … |
The End.