6,741 Posted Topics
Re: You can still use the template parameter for a nested type: [code] #include <iostream> template <typename Type> class Array { public: Array() { std::cout<<"Default Array<>\n"; } }; template <typename Type> class Array<Array<Type> > { public: Array() { std::cout<<"Specialized Array<>\n"; } }; int main() { Array<int> rob; Array<Array<int> > bob; } … | |
Re: You've introduced a virtual inheritance ambiguity. Since those member functions are virtual from the base, and both sides of this triangle you've created override them, which of the overrides will be inherited by the bottom of the triangle? The error is telling you to add a final override in derive: … | |
Re: [ICODE]const char *msg[/ICODE] is a pointer to const char. [ICODE]char* const msg[/ICODE] is a constant pointer to char. In the former case the object being pointed to is const and cannot be modified, but the pointer can be changed to point to another object. In the latter case the pointer … | |
Re: It's worthless as far as testing your competence with C++. Last I head, many of the questions were flat out wrong, or didn't include the correct answer. So it's really a test of guessing what the test creator wanted as an answer. | |
Re: A default constructor is one you can call without any arguments, either because it actually takes no arguments, or all of the parameters are defaulted. Your Person class has a constructor, but it has one non-default parameter. | |
Re: There's a newsletter emailed to members each month. As for the interview, it varies. | |
Re: [QUOTE]you know that in c++ you cant use " & " alone for the "and" purpose right?[/QUOTE] You can (with proper care), but it's not short circuited and tends to be confusing. I don't know anyone who would let & instead of && slide during a code review. | |
Re: If all func does is return an index, why do you need to pass a pointer to void? I recognize that you want to perform a random shuffle on a generic array, but you're overcomplicating things. Compare and contrast: [code] void shuffle(void *arr, size_t n, size_t size) { unsigned char … | |
Re: [QUOTE]its not mandatory that it should return int.[/QUOTE] The specific rules are subtle and varied. It's far easier to return int and guarantee that your code will work everywhere than to be stubborn and risk introducing bugs. [QUOTE]also its not necessary to maintain the syntax here..[/QUOTE] Yes, yes it is. … | |
Re: [URL="http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_sorting.aspx#merge"]Clicky[/URL]. | |
Re: Holy crap, is it airline seating assignment season again? Oh, how time flies. :icon_rolleyes: The problem is trying to memset an array of arrays of std::strings. I'd strongly suggest forgetting that memset exists in C++, because it's totally not worth the headache. Consider something more like this for your constructor, … | |
Re: [QUOTE]CONVERT THIS QUICK SORT PROGRAM INTO PARTITION OF 3,5,7OR 11 ELEMENTS.[/QUOTE] So you've pinched some code from the web and now want us to make it do what you need to get a good grade? Hmm, no. Do your own damn homework. | |
Re: [QUOTE]If a condition is tested with or, and the first condition is met, are the further conditions tested?[/QUOTE] && and || are both short circuited. They'll stop evaluating when a definite result is achieved. | |
Re: You need to do the work in a separate thread from your UI. That way the UI is still responsive while long running tasks are being performed in the background. You don't have to make the background task faster, just alter users' perception of application performance by avoiding the "Not … | |
Re: Error 1 is a little subtle. qsort expects a pointer to a function, which sortarr is not. Due to how C++ handles member functions, the type of the address of Sort::sortarr is different from a typical function pointer. Note that doing what the error suggests and using a pointer to … | |
Re: In my opinion, the best way to welcome someone is to treat them like any other community member. That means more than any welcome message or special treatment. | |
Re: [QUOTE]1. I want to use fgets(text, MAX_WORDS, stdin) to read in a string file, where my array is text[MAX_WORDS]. But is there a way to make stdin a pointer instead to a 2nd array which can be a buffer?[/QUOTE] You mean some kind of sgets that reads from a string … | |
Re: [QUOTE]Can anyone tell me what is meant by "partition" in the above?[/QUOTE] It's the partition step of quicksort. If you don't know what that means, you need to do some research and learn how quicksort works. Otherwise an implementation is impossible without stealing code and hoping it's correct. | |
Re: You realize that's a terribly leading question, right? There's only one gcc compiler. There are several versions, but the latest stable release is typically recommended. Perhaps you mean which IDE that packages with gcc should you download? In that case you'll either get recommendations to use a straight text editor … | |
Re: With that implementation, beware the next push, because it will overwrite the object pointed to by the previous pop. Mysterious data corruption is an insidious bug. | |
Re: So what are you expecting 0 to represent as a string? | |
Re: [QUOTE]I know I am way over thinking this, but could I get a hint?[/QUOTE] Why do you need a second function when the first does what you need (summing digits)? The program's driver would simply call DigitSum in a loop until the stopping case is met, unless you have a … | |
Re: [QUOTE]Do all compilers support it?[/QUOTE] A better question is "do all compilers that matter for your project support it?". [QUOTE]Usually the suggestion is to use both pragma once and include guards[/QUOTE] What happens if the compiler supports [ICODE]#pragma once[/ICODE] but it doesn't do the same thing? That's somewhat unlikely, but … | |
Re: I'm having trouble nailing down what your problem is. Are you having trouble with creating an AVL tree, or is the issue using string keys for a working AVL implementation? | |
Re: [QUOTE]Im trying to write all that info to the file in random access[/QUOTE] If you want random access, you have to specify where in the file this record is to be written. But random access writing isn't as simple as you seem to think. You'd be better off either using … | |
Re: I'm not sure what rock you've been living under, but smartphones have been used heavily in businesses for well over a decade. Note that the explosion of affordable laptops made IT security pros very nervous too. Technology evolves and so do the ways of using it. I think the best … | |
Re: You have no formatting of the file beyond a whitespace separated sequence of values, so the loop is trivial: [code] while (fscanf(input, "%lf", &value) == 1) { /* Process the value */ } [/code] fscanf will return the number of converted items, so if you're asking for one item and … | |
Re: If all you want is to read hexadecimal values like you would decimal values, the std::hex modifier works for both input and output: [CODE]#include <iostream> int main() { int value; while (std::cin>> std::hex >> value) std::cout<< std::hex << value <<'\t'<< std::dec << value <<'\n'; }[/CODE] | |
Re: Find several contractors and get quotes in person rather than throw out a job listing. They'll be able to help you nail down exactly what needs to be done in the process of writing up a quote and you'll likely be happier. | |
Re: Here's a quickie example that might help: [code] #include <stdio.h> #include <string.h> void copy(void *a, void *b, size_t size, size_t n) { unsigned char *pa = a; unsigned char *pb = b; while (--n < (size_t)-1) { memcpy(pb, pa, size); pa += size; pb += size; } } int main(void) … | |
Re: Policies help to avoid utter chaos. Feel free to fluff that up into a paragraph, but that's the core of it. | |
Re: At least you're not hiding your laziness, but this forum is for helping people who want to write code, not giving freebies to leeches who just want a solution. | |
Re: [QUOTE] date: 03/21/2011 first name: John Last name: Connor Dollar amount: 21 Change: 14 payee: first financial should output to: [code=text] 03/21/2011 John Connor 21.14 first financial [/code] [/QUOTE] With the current setup, you can use the length of the date as your field width because it will always be … | |
Re: [QUOTE]Is the use of two pointers against the whole idea of a circuluar linked list ?[/QUOTE] Not at all. As long as the end of the list points back to the beginning, it's a circular list. You can certainly use an end pointer to simplify the implementation without making it … | |
Re: [QUOTE]Anyone have an idea how see if a 32 bit integer has an even or odd number of 1 bits using ONLY bitwise operations?[/QUOTE] First, ! and + aren't bitwise operators. Second, yes, I know several ways of doing this. Third, since this is invariably a homework question, the task … | |
Re: Please tell me where either [B]left[/B] or [b]right[/b] are modified in the following loop: [code] while(left<right) { loc=partition(a,left,right); quicksort(a,left,(loc-1)); quicksort(a,(loc+1),right); } [/code] If your answer is "nowhere", then you get a gold star. :) That loop shouldn't be a loop at all, it should be a simple if statement and … | |
Re: [QUOTE]Can anyone answer the question , I need to answer as well [/QUOTE] Whether you need the answer or not doesn't change the fact that we don't do other people's homework until they've demonstrated sufficient effort in completing it themselves. | |
Re: Let's say you have a structure definition [ICODE]struct { int x; } a[10];[/ICODE]. For the sake of indexing, a is a pointer, so you can get to an element through either the [ICODE]a[<index>][/ICODE] or [ICODE]*(a + <index>)[/ICODE] methods. At that point you have a structure object, so the . operator … | |
Re: You need to parse the input. There are two simple methods, starting with straight operator>>: [code] #include <fstream> #include <iostream> #include <string> int main() { std::ifstream in("test.txt"); if (in) { std::string field; while (in>> field) { if (field == "UP") std::cout.put('\n'); else std::cout<< field <<'\t'; } } } [/code] The … | |
Re: Structures are an aggregate type. You need an instance of the structure before you can access any members. Notice that [B]rchild[/B] and [B]lchild[/B] are referenced without any struct instance as if they were not members, You probably want something more like [iCODE]ptr->rchild[/iCODE], for example. You also can't use a variable … | |
Re: The associative containers in the standard library are equivalent to dictionaries in other languages. | |
Re: I don't understand either. Maybe you should specify what "the error" is as well as what "the input" is and what "the output" you were expecting. :icon_rolleyes: | |
Re: [QUOTE][CODE] while (!infile.eof() && (c< MAX_VEHICLES)) { getline(infile, inputLine);[/CODE][/QUOTE] This is a buggy pattern. eof() doesn't evaluate to true until after you've tried and failed to read past end-of-file, which means you'll process the last record of the file twice. The worst part is that the correct pattern is shorter … | |
Re: GetAsyncKeyState only tells you which key was pressed. Casing is determined by combining those keys with the shift key and the caps lock key. You'll need to check those two as well and output the correct case accordingly. | |
Re: [QUOTE]//x = nxt_blck; //if i declare this it gives me a sg fault?!?[/QUOTE] That's not where your segmentation fault is. It's on the next two lines: [code] Node *result; // Declaring uninitialized pointer result->setState(state); // Using uninitialized pointer [/code] A segmentation fault means that you're accessing memory outside of the … | |
Re: [QUOTE]or just the number of elements needed[/QUOTE] What size is each element? Since void doesn't have a size, there's no way to tell without a parameter specifying the element size (calloc, for example). realloc has no such parameter, so by deduction we can conclude that the second parameter refers to … | |
Re: To answer the other half of the question, you're not allowed to post on Daniweb if your account is banned. It's the web forum equivalent of sitting in time-out. | |
Re: One thing to note is that sizeof(unsigned char) is absolutely going to return 1, every time. You can simplify the expression by removing that part. Now, when malloc returns NULL on a modern OS, that's typically indicator of fragmented memory. You have memory to spare, but it's fragmented into small … |
The End.