2,898 Posted Topics
Re: the (int) cast is from C, and is not recommended in C++ for good reasons. Use the "functional" casting: [CODE] //check the video info header Width = int(&pVideoInfoHeader->bmiHeader.biWidth); Height = int(&pVideoInfoHeader->bmiHeader.biHeight); //break point here [/CODE] But in this case, long is implicitly convertable to int, so the cast is useless … | |
Re: There are some tools for "code refactoring", I have looked for good ones that are free or opensource, but to no avail. Visual C++ has apparently very good tools for code refactoring, but I have not used them. In this case, you want to use a serialization library like the … | |
Re: Oh... small piece of code, lots of problems: [CODE] struct Person { char* name; //this is a pointer to a char (or array of char, with null-termination) int age; //For good practice, use parameter names that don't conflict with data member names. Person(const char* aName, int aAge) //notice the "const" … | |
Re: Of course you can! That's the whole point of semaphores: to synchronize threads. A named semaphore is convenient because all you need to do is call sem_open with the same name and you get the same semaphore for two, three, four, or a gezillion threads. From [URL="http://linux.die.net/man/7/sem_overview"]this link[/URL]: [QUOTE]A named … | |
Re: Download and install the latest version with MinGW the file named "codeblocks-10.05mingw-setup.exe" from the links [URL="http://www.codeblocks.org/downloads/26"]here[/URL]. | |
Re: These are the faulty lines: [CODE] out.write("\t",4); .. out.write("\n",4); [/CODE] Where is the 4 coming from? The length of "\t" is 1. The "Wa" is probably corresponding to some memory that is stored after the literal "\t" and "\n" which both take 2 bytes (one is \t or \n and … | |
Re: Well, I used to work with C++Builder (the older versions, like 5 to 7) and I have always like it much better than the Visual C++ versions of the time. I don't know how much both have changed since and how they compare now. But I would say that C++Builder … | |
Re: In your InitGeo function, you call sinf(theta) several times and theta IS IN DEGREES! That's your problem. use the angle variable instead. In the future, it might be a good idea to get used to using only radians for everything, degrees are meaningless and useless most of the time. The … | |
Re: As far as I know, this code is fine on a standard implementation. It seems that the underlying problem is that aCC doesn't have a "less" comparator for string types. Try implementing your own comparator for the string class and pass it as template argument in the declaration of _map2. | |
Re: Pretty nice! But I have a few things to point out: First, gcc complains with this code because of those "typename typedef .." statements at the beginning of the MergeSort class. These don't make sense as you posted them, and I don't understand why your compiler would not complain. As … | |
Re: Why do you need two operators <<? I mean if you put the code for the second one into the first one, you will only need to do "fileOut << d;". Moreover, the second call "<< d.beamlets" is not going to work because beamlets is a private member of the … | |
Re: I can't help much, but I can say that usually what you are referring to is called an "edit box" not a text box. That might help you in your web search. | |
Re: I'm not going to be able to help with the details of the asm code (is there a reason why it's programmed in asm?) but I have a bit of know-how on serial ports. Did you try to implement the receiver in C++ code? From what I see (from the … | |
Re: First, pArray should be declared as unsigned char* (no double stars). Allocate for pArray with new unsigned char[size]. If you are reading the characters as each being an individual number from 0 to 255 in binary format (since this is how you open the file), then forget about adding a … | |
Re: Doesn't Borland have newer products like CodeGear RAD Studio and C++ Builder 2010, now from "embarcadero" at [URL="http://www.embarcadero.com"]www.embarcadero.com[/URL]. I think those allow you to take old VCL/CLX applications and port them to the newest library versions. Of course, these have a big price tag too! Visual C++ Express and Code::Blocks … | |
Re: it must be a typo of some sort, because this code is fine and should compile. This will compile (I tested it): [CODE] #include <iostream> struct structA { int val; }; struct structB { double val; }; class classA { public: int function(structA * ptrA) { std::cout << "function_A called!" … | |
Re: These messages are useless, what are the "error" messages? the "in member.." just tells you where the erroneous code was called from. You should have later on some messages saying "error" and giving the file and line, e.g. "my_header.h(42)" for an error in my_header.h at line 42. Generally, you should … | |
Re: On the main() function, [URL="http://stackoverflow.com/questions/1765686/correctly-declaring-the-main-function-in-ansi-c"]see this SO-thread[/URL]. Your prof is wrong on this matter. Even the original C standards have always defined main as returning an int, although the old standards allowed to omit the return type, in which case the int type was implied. This was changed in C99 … | |
Re: I don't know of any way to do this... try [URL="http://www.cplusplus.com/reference/iostream/"]iostreams[/URL] in this case, they allow you to set precision formats as functions like setprecision(3) or whatever, this will allow a variable number. | |
Re: @Garrett: >>there's no way to do it without using a pointer vector For the record, Nothing is impossible in C++: [CODE] class SuperClass { public: class Impl { public: virtual void someMethod() = 0; virtual Impl* clone() throw() = 0; virtual ~Impl() throw() { }; SuperClass Encapsulate() throw() { return … | |
Re: It works fine on gcc in linux. Try using [URL="http://www.codeblocks.org/downloads/26"]Code::Blocks[/URL] instead of Dev-C++, which is outdated and has several issues with Windows Vista/7. | |
Re: Tested it with g++ -std=c++0x and g++ -std=gnu++0x, in both cases: error: cannot convert ‘<brace-enclosed initializer list>’ to ‘const int*’ for argument ‘1’ to ‘void someFunction(const int*)’ I added const because otherwise it would never work for sure. | |
Re: Yeah, easy. A string is a list of chars. All you have to do is: [CODE] char recvbuffer[512]; MessageBox(hWnd, recvbuffer, "Character to String"); [/CODE] | |
Re: First logic feature to see is that it is always symmetric about the central value in one sequence, so you will probably just need to store or compute one half of each row (from start to middle) and repeat in reverse for the remainder of the row (taking into account … | |
Re: Well from my understanding, you are sharing the objects between your different objects, i.e. the Graph and Edge objects contain pointers to shared Nodes. In this case, of course storing the objects directly is out of the question, or at least one of the two objects that hold the shared … | |
Re: And you should probably also make the operator == constant as well: [CODE] bool operator==(const Node &) const; //.cpp bool Node::operator ==(const Node& node) const { return node.getName() == getName(); }; [/CODE] | |
Re: In this case, if the two objects are of the same class, then you can fairly easily just pass one object to a method called on the other and act on both objects in that method. In code: [CODE] class player { .. all the stuff you posted .. public: … | |
Re: I think arkoenigs answers makes a lot of sense, and I trust that he's right. By opposition to C and C++, look at Pascal and Object Pascal (or Delphi). Delphi has nested functions because it was extended from Pascal that already had those too. It's a matter of linking strategies … | |
Re: If you want to modify the pointer primary (which was in either primary->left or primary->right in the recursive caller), you need to pass the pointer by reference. Because modifying primary in the above code snippet is not going to affect the original tree that you pass to Merge. So, simply … | |
Re: >>My class (or should I use struct?) Well classes and structs are essentially the same in C++, the only difference really is that by default all data members declared in a class are private, while the default for struct is public. So in your code, you won't be able to … | |
Re: Well first, you need types for "position,item,success" unless these are types already, but I doubt it from the names. Intuitively I can guess it should be "(int position, aDataType item, bool& success)". Then, "List" here is repetitive, I would take it out. As in: [CODE] class List { public: bool … | |
Re: [QUOTE]I am using a switch statement, so they must be constant[/QUOTE] Then don't use a switch statement. The switch statement is just shorter (a bit) to write then "if () {} else if () {} ...", but it's fundamentally the same. So if it is not convenient for you, don't … | |
Re: For any platform, you can use [URL="http://www.boost.org/doc/libs/1_43_0/doc/html/date_time.html"]Boost Date_Time[/URL] library to do anything you want, and you can even get time in MICROSECONDS. | |
Re: The output is not exactly 0.0 because floating-point values on a computer can NEVER be exact. You can [URL="http://www.cplusplus.com/reference/iostream/ostream/"]format the output[/URL] such that it doesn't display in scientific notation (like with a big negative exponent, as I assume it does now). | |
Re: First of all, the memory leak comes from this line: [CODE]m_pText = new char[nTotLen + 1];[/CODE] Because before this line, m_pText already points to allocated memory, so you need to add a delete statement before: [CODE] if(m_pText) delete[] m_pText; m_pText = new char[nTotLen + 1]; [/CODE] If you have also … | |
Re: [URL="http://www.mysql.com"]MySQL[/URL] is another simpler and free database server too. My advice is to browse your GUI library for built-in database functionality (I know Borland VCL has all sorts of nice GUI widgets for database programming, but it's a bit outdated (I haven't done database stuff for a long time), I'm … | |
Re: Well basically, for rendering it (displaying it) there are two main libraries, OpenGL and Direct3D. I am familiar with OpenGL, which also has a few possibly useful utility tools like GLUT (some extra functions, and cross-platform windows), GLUI (some functions for User Interfaces), and OpenInventor (for some tools to load … | |
Re: OP>>I would like to avoid using atoi function. You can use [URL="http://www.cplusplus.com/reference/iostream/stringstream/"]stringstream[/URL] for converting between strings and other types, in the same way you take input from cin and output to cout. For the rest, I think AD answered pretty well. | |
Re: Your problem is that a function pointer is essentially a C feature and does not support methods (that is a function acting on an object). So you can only make function pointers to static class methods or global (or namespaced) functions. >>As i think you can see i basically want … | |
Re: This building tool is "autoconf", which is really bad compared to cmake.. but if you don't have a choice. I have worked a little with this, but not so much. The file you are looking to modify has the name "Makefile.in" in the folder where your additional source code is … | |
Re: I agree with Narue, I have never heard of legitimate certifications for C/C++. In my experience, only experience rings well in employers ears. But personal experience counts too, don't be satisfied with the exercises from a course or book, take some initiative to start your own projects and get experience … | |
Re: What you need to include is [URL="http://www.cplusplus.com/reference/clibrary/ctime/"]<ctime>[/URL]. | |
Re: I prefer spaghetti bolognese to spaghetti code... boy, isn't this a mess! I think you will have to start from the start again. This is object-oriented programming. So first of all, you need to decide what data and functionality go together. In this case, it's not a very tough software … | |
Re: p->next will be NULL for sure, do you see any line in addNodeAtFront() which starts with "next =".. the answer is no. So next will start with the value NULL and will remain that way. I think you have mixed up front and next in your addNodeAtFront().. not entirely, but … | |
Re: @StuXYZ.. just a little important correction, the OP should add: [CODE]virtual ~baseClass() {}; //notice the ~ for destructor[/CODE] check also [URL="http://www.daniweb.com/forums/thread300907.html"]this thread[/URL] on a very similar topic. | |
Re: You can reinterpret_cast your char pointer to an int pointer or void pointer to print out its address. | |
Re: Don't be discouraged, your code is quite good! One mistake that solves the problems with option 2 and 3: in several places, when dealing with the marks array, you do the following for example: [CODE]for(int i=0;i<5;i++,average+=marks[i]);[/CODE] Putting the "average += marks[i]" within the for-statement's third section is not good. The … | |
Re: >> what is the difference between (i) *p++ & ++*p ++*p : reads as follows: pointer p is dereferenced to give the variable that it points to, then this variable is incremented and its final value is returned. *p++ : reads as follows: since postfix increment has priority over dereferencing, … | |
Re: Narue is right, the clear() function is not specifically guaranteed to free all the memory because for memory-optimization purposes, in general, the vector class can keep a large amount of allocated memory in anticipation of future reuse of the memory. So calling clear(), does call all destructors of the elements … |
The End.