3,183 Posted Topics
Re: > When a's destructor is not virtual and either b's or c's IS virtual, the program crashes. I'm not sure why this one happens. I don't know off the top of my head, but I'd guesstimate that this invokes undefined behavior somehow and crashing was the result. > When a's … | |
Re: > test.txt is stored in the same directory as my XCode project. But is that the current working directory for XCode (assuming you're running directly from the IDE)? Use perror() to get a more useful error message: FILE* f = fopen("test.txt", "r"); if (f == NULL) std::perror("Error opening file"); I … | |
Re: > typedef long static_cast<*stringFromString>((int, char*)) __cdecl; This is completely nonsensical. Casting is a form of coercion of *objects* to another type. The bytes of the *object* are interpreted as the new type. A typedef is not an object. > SmartSetup((char*)World.c_str(), (char*)",f5", 765, 503,(char*)""); > //TO: > SmartSetup(static_cast<char*>(World.c_str()), static_cast<char*>(",f5"), 765, 503, … | |
Re: > Are the DaniWeb registration passwords hashed and salted? Yup. | |
Re: Parameter names aren't required in a function declaration, though it's generally viewed as poor style to take advantage of that (mis)feature. You can also omit the parameter name if you don't use the parameter, even if it's a definition, which can be useful every now and again to match interfaces: … | |
Re: > I would recommend that moderators get more involved with thier members, not only in answering questions, but also in the voting and commenting process. I'd be shocked if most or all of the moderators didn't already participate heavily in this way. One of the reasons mods attracted attention for … | |
Re: I suppose the optimal type would be the one std::vector exposes for you: std::vector<T> v; ... // Use the provided size_type for (std::vector<T>::size_type i = 0; i < v.size(); ++i) { ... } That's rather verbose, so you can hide it behind a typedef prior to C++11, or use auto … | |
Re: Your initial allocation loop iterates far too many times. The overall process looks fine though. I'd write it like this: int rows = numCouples * 2; int cols = numCouples; int** ratings = malloc(rows * sizeof *ratings); // Check if malloc() failed... for (i = 0; i < rows; ++i) … | |
Re: "Help me please" is not a good question. Please be specific about what you want help with. I'd also recommend reading [this tutorial](http://www.catb.org/~esr/faqs/smart-questions.html) on how to ask a smart question. | |
Re: Please direct replies here: http://www.daniweb.com/software-development/csharp/threads/426133/csv-file-to-database | |
Re: > My theory is that those libaries are needed for those 'built-in' functions and that those libaries do not exist on my system. Yup. Your only two options are to find libraries that implement the functions being called, or simulate the functionality by writing definitions for those functions manually. | |
Re: > how the compiler searchs for a file when we write fopen("filename","r"); It doesn't search, you give it a specific file name. As far as relative paths, that's fairly standard behavior in that the *system* (not the compiler) will attempt to open the specified file in the current working directory. | |
Re: What operating system are you using? I'm running Chrome on Windows 7 64-bit and selection seems to work as expected. | |
Re: An adapter is really nothing more than a wrapper around another class that exposes a specialized interface. So at its simplest, a stack might be implemented like so: template <typename T> class Stack { public: bool empty() const { return _data.empty(); } void push(T const& x) { _data.push_back(x); } void … | |
Re: I can't reproduce the error because too many things are missing. Can you boil it down into a small and complete program that's compilable as-is? Also, what compiler are you using? | |
Re: > Remove conio.h and _getch and it should compile for you. If you can remove parts of a program without affecting it's functionality or usefulness, were those parts really needed in the first place? ;) But no, it won't compile for anyone who's not using Visual Studio. Even then, Visual … | |
Re: Look into how qsort() works, as that's the solution for C. However, C is very inadequate for dynamic typing, so you'd probably be better off looking for a different implementation language or ditch the "accept any type" option in favor of something better suited to C. | |
Re: In proper socratic fashion I'll ask you this: what happens to an ifstream object when it goes out of scope? | |
Re: You'll want to convert both a and b to strings, concatenate them, then convert the result back to an integer. Here's an example using string streams: #include <iostream> #include <sstream> #include <string> using namespace std; int main() { int a = 4; int b = 5; ostringstream oss; oss << … | |
Re: > sscanf(puppy,"%[^|]%f", &p, &num); Try this instead: sscanf(puppy,"%[^|]|%f", p, &num); You forgot to extract the pipe character. Not to mention that the address-of operator is unneeded on `p` because it's already a pointer to char. | |
Re: I've committed a fix to our code repository. It should make it to production pending Dani's approval. Thanks for the report. :) | |
Re: You forgot to post the code. By the way, is this a code snippet for the benefit of others or do you have a question about the code? | |
Re: > Here, in the call to the function, what are we passing as an arguement, is p is here a char pointer or a char ** ?? In the first call the argument is `char*`. In the second call it's `char**`. An important difference to note is with multidimensional arrays. … | |
Re: The short answer is you can't. The long answer is you can if you aren't pedantic about it. An array can be copied by value by wrapping the array in a structure and then passing an instance of that structure. When the structure instance is copied, the array goes with … | |
Re: It seems to work on my end (noting that I removed readData() and built the vector manually). Can you post some sample data that exhibits the problem? | |
Re: > First, why does this not cause a stack overflow? I'd wager that the empty function call was optimized away. You *might* be able to turn off all optimization switches in your compiler and get it to overflow. > Two, What is the difference between the two below? The first … | |
Re: > erm i learn new thing, its a bad idea to use "using directive" inside a class declaration, because this can leads to ambiguous functions/statements inside the main program. That argument only applies if you reuse standard library names, which generally isn't a good idea in the first place. While … | |
Re: > how to write it :) Is this your question? If so, you'll need to put forth a little bit of effort. I doubt anyone is willing to write a ternary tree for you because you're too lazy to make an attempt. | |
Re: Gaack, I'm sorry. I accidentally killed your code when I changed this article from a code snippet to a discussion thread. Would you mind posting it again as a reply? | |
Re: What's the logic for the path? Is it the shortest path between A and B? Longest? Ad hoc based on input? | |
Re: You pretty much nailed it for a simple class. It gets quite a bit more complex when construction, destruction, inheritance, polymorphism, and especially multiple inheritance enter the picture. A good book covering the topic is [this one](http://www.amazon.com/Inside-Object-Model-Stanley-Lippman/dp/0201834545). | |
Re: > Q1. Languagess are system software or application software? Neither. Languages aren't software at all, they're abstractions designed to simplify the task of humans giving instructions to a computer. A programming language is nothing more than a set of grammatical rules that, when consumed by a compiler or interpreter, represent … | |
Re: > Why dont we use '&' in the case of strings in function scanf ?? > > e.g. :- > > scanf("%s",date); > > here date is a character arraymeans string. Because date is already a pointer in this case. There's no need to add another level of indirection with … | |
Re: The syntax for PHP is derived from the C family of languages, Ruby isn't. You'd feel more comfortable with PHP, but it's generally a good idea for programmers to have some familiarity with different language families. | |
Re: 9 times out of 10, a linker error means you failed to define something that was declared before it's usage. Very often this is due to a static class data member: class foo { static int bar; }; int foo::bar; // This external definition is required somewhere (ideally in a … | |
Re: > Can you write a program in C++ and have another part written in C and compile them into a single executable file? Yes. The two would be compiled into object code separately, then linked together. However, that's not the hard part. The hard part is making sure that the … | |
Re: > I'm writing it so that I don't have to worry about deleting anything everytime I allocate. While writing your own smart pointer is a good exercise, it shouldn't be preferred over the ones already available in C++11 and Boost. I'd recommend studying the interface for those and how they … | |
Re: set_union() assumes that the output iterator points to a collection with enough existing space to hold all of the results. If you're planning on using an empty vector or have set_union() grow the vector then you'll want to do it through a back inserter. | |
Re: I was able to reproduce the issue on Chrome Beta 20.0.1123.27. Clearing the cache corrected it. If you're affected, please try clearing your browser's cache and let us know if the problem persists. | |
Re: > Is it possible to overload one operator more than once? Yes, but only if the parameter types are unique. Operator overloading is no different from regular function overloading in that the signature (not including the return type) must be different for overload resolution to be unambiguous. | |
Re: I'm going to go into pedantic mode for a bit. Apologies if either of you are offended in the process. > `#include <conio.h>` C is a widely portable language, which means it's possible to take code and compile it on a multitude of operating systems and compilers without any changes. … | |
Re: > numPerms\[ii] = str; `str` is a pointer, that pointer holds the address of `word` from main(). After RecursivePermute() runs to completion, every pointer in `numPerms` points to the same address. Given that you've already allocated memory to each element in main(), you can fix both the problem and the … | |
Re: Well, you could take advantage of the way the numbers are patterned. Notice how your triangle fits perfectly if you replace everything less than or equal to N with asterisks, where N starts at 6: int j; int x = 6; for (int i = 1; i < 6; i++, … | |
Re: I've wondered that as well, but if it were in Software Development I'm sure someone would ask why there's not a database subforum in Web Development. ;) Anyway, my conclusion was that it's just an artifact of history where Dani simply chose to put that subforum there instead of somewhere … | |
Re: > When I use Chromium, I am unable to login. > Today I tried my luck with Firefox and it worked. > But I am not sure what the problem with Chromium is.. This is mostly for my own curiosity, but it could also benefit troubleshooting: have you tried Chrome … | |
Re: Some compilers have an option to rename the entry point, but I'd question its usefulness in all but the most niche cases. > And what, exactly, is the purpose of the main part, anyway? To provide an entry point into the program. That's really it. The C++ runtime has to … | |
Re: setw() is an absolute field width, not something based on tab stop boundaries, so you'd need to calculate the correct field widths for even alignment. You can also use the '\t' escape character to print a tab that will adhere to tab stop boundaries: cout << setw(23) << left << … | |
Re: Please provide evidence of having attempted to solve this homework question on your own. | |
Re: I'm not sure I understand the requirement. It looks like start and finish are related, in which case sorting by finish time would be more meaningful like this: #include <stdio.h> #include <stdlib.h> struct ElapsedTime { int start, finish; }; int compare_elapsed(void const* a, void const* b) { struct ElapsedTime const* … |
The End.