6,741 Posted Topics
Re: [QUOTE]Is it mandatory to use operator= overloading every time i write a copy constructor?[/QUOTE] Unless you're going to make operator= private, it's a good idea to include it as well as a copy constructor and a destructor. Because if you [i]need[/i] a copy constructor, more often than not you need … | |
Re: [QUOTE]But when I run the release version it gives me an error after having run a while.[/QUOTE] Not only is your bug dependent on debug vs. release, it's also intermittent (as I understand from "having run a while"). How large is the code base? Are you able and willing to … | |
Re: Without error handling: [code] char **exParam = malloc(n * sizeof exParam); char **exText = malloc(n * sizeof exText); for (i = 0; i < n; i++) { char *param = strtok(lines[i], "#"); char *text = strtok(NULL, "#"); exParam[i] = malloc(strlen(param) + 1); exText[i] = malloc(strlen(text) + 1); strcpy(exParam[i], param); strcpy(exText[i], … | |
Re: Darth Vader became drastically less powerful due his injuries, which included loss of flesh. Since midichlorians have sadly been introduced into canon, it's probably safe to say that losing a limb [I]does[/I] decrease midichlorian count, which in turn makes a Jedi lose power. ![]() | |
Re: [ICODE]itk::Image<T, D>::Pointer[/ICODE] is a dependent type, meaning it depends on template parameters for the specific type definition. In these cases you need to specify that it's a type rather than an object: [code] template <class T,int D> typename itk::Image<T, D>::Pointer CreateITKImage(int *pnSize, double *pdSpacing = NULL) { // ... } … | |
Re: Note that C++ doesn't use references for objects by default, so [iCODE]Vector campos;[/iCODE] in C++ is equivalent to [icode]Vector campos = new Vector();[/icode] in Java. With that in mind, it should be obvious that your Vector class doesn't have a default constructor even though you try to call one. | |
Re: [QUOTE]1. What is the purpose of using a DLL over a .lib or just a single .exe?[/QUOTE] Smaller executable size, smaller memory footprint, and easier update deployment of the library code (eg. the executable need not be recompiled). [QUOTE]2. What exactly (in VC++) does __declspec(dllimport) and __declspec(dllexport) do and where … | |
Re: You're working with single characters rather than strings. Try changing the type of npcname and actid from char to std::string. Also note that the loop won't work too well with strings. You probably want to check all characters. | |
Re: Header files are only there for convenient access to type and function declarations, they don't (rather, shouldn't) contain definitions or any executable code. As such, it's often easier to lump everything in a single *.c file until you have a working draft, then break out the declarations into a header. | |
Re: [CODE]Why????[/CODE] It might make more sense if you convert to a while loop: [code] i = 1; while (i <= 20) { b = i * 30; printf("b é uguale a: %d = %d * 30\n\n",b, i); ++i; } [/code] i is always incremented after the body of the loop … | |
Re: Lazy much? Your code is fundamentally very C-like, so the conversion should be little more than changing couts to printfs, cins to scanfs, and using pointers instead of references. At a quick glance, those are the only changes necessary to compile as C. | |
Re: If you're replacing every instance of a single character with another single character, std::replace from <algorithm> is better suited than any of the std::string::replace overloads: [code] #include <algorithm> #include <iostream> #include <string> using namespace std; int main(void) { string test; test="this is a test"; replace(test.begin(), test.end(), ' ', '~'); cout … | |
Re: [QUOTE]How would you use this?[/QUOTE] It's less useful in C++ than C89, where all variables must be declared at the beginning of a block. Though unnamed blocks are useful if you want to force a shorter lifetime on resource intensive objects: [code] // Lots of code { ResourceIntensive ri(...); ri.do_stuff(); … | |
Re: Take all of the declarations and put them in a header file: [code] void *newMalloc(size_t vol); void newFree(void *adPtr); void save(); void search(); void *findSpace(); void freelist(); [/code] Add any includes that are required by the declarations: [code] #include <stddef.h> // For size_t void *newMalloc(size_t vol); void newFree(void *adPtr); void … | |
This is an example of using a binary index file to speed up random access of lines in a file. The file is indexed one time, where the position of the start of each line is stored in an index file. Subsequent requests for a get the position from the … | |
Re: [CODE]i was kind of hoping for the specific name of the algorithm they use[/CODE] You're not the first person to ask, and Apple hasn't been forthcoming, so it's a safe bet that they don't want you to know. | |
Re: 123 % 10 is 3. 123 % 100 is 23 23 / 10 is 2. 123 / 100 is 1. Extrapolate an algorithm from that. | |
Re: [QUOTE]Would it be okay if I asked for advice on different problems I am having with the calculator and how to program certain things on it without providing a code?[/QUOTE] Those kinds of questions are tricky to ask right. As long as you keep it on a conceptual level and … | |
Re: >but I'm not sure if that's right. Who cares? Try it and see if it works. This program is small enough that you can comfortably experiment. >I haven't actually wrote code for it yet, just trying to get an idea of where to start. You have an idea of where … | |
Re: Could you perhaps ask a specific question? Right now it looks like you're asking for some charitable soul to do your homework. | |
Re: guard_rec is an array, not a struct instance. You need to index into the array before any member access can be done: [code] /* Where i is a suitable index */ guard_rec[i].first_name [/code] | |
Re: [QUOTE]Is it possible to have a pointer to something (say a string) that is on the hard disk?[/QUOTE] For a very liberal definition of "pointer", yes. But if you mean a C++ pointer type, no. | |
Re: [QUOTE]1) Base* ptr = new sub; Kinda confused about this - and also, how/why it is useful to have a base class pointer storing the adress of a sub class. Perhaps someone could clear this up for me?[/QUOTE] Generally, it's useful when you want to handle multiple related types (which … | |
Re: You can make a public globals class with public static fields representing the "global" variables. Not exactly a good design, but it works. | |
Re: Start by getting a handle on socket programming: [url]http://beej.us/guide/bgnet/[/url] | |
Re: For starters, you're not defining boundaries on the string, so you'll get false positives for an embedded match. Here's one from my personal library of regular expressions, it more or less rolls your two patterns up into one (but notice the boundary checks): [code] @"^\(?(?<NPA>[2-9]\d{2})(\)?)(-|.|\s)?(?<NXX3>[1-9]\d{2})(-|.|\s)?(?<NXX4>\d{4})$" [/code] | |
Re: I don't see how searching for a duplicate before insertion is problematic. Just traverse the list and if you get to the end, append a new node: [code] struct node *append_no_dup(struct node *head, struct node *new) { if (head== NULL) head = new; else if (compare(head, new) != 0) { … | |
Re: What is maths.h? That's not a standard header, unless you meant math.h. | |
Re: If you want a general code review, be sure to ask for it specifically to avoid confusion. I and a few others occasionally tear down programs line by line, point out issues, and suggest better ways of going about a solution, but it's ideal if the program is relatively short … | |
Re: You realize that getchar is reading one character and returning the code value of that character, right? If you type "100", the values you get are likely to be 49, 48, and 48. Is this intended? Because it raises red flags when I read it. | |
Re: Simply churn out code, or code effectively? I can go four hours or so before a break is needed to maintain quality, but if the code can suck ass an all day caffeine fueled code orgy isn't improbable. I refuse to [i]not[/i] get my eight hours of sleep though, so … | |
Re: I'd speculate that $@ (your target) is a Windows-style path with the "<drive>:\" pattern. The colon from Windows paths can cause this error because suddenly you're looking at an unexpected separator in the pattern rather than a complete target. What does your make invocation on the command line look like? | |
Re: [QUOTE]Is it ok to directly copy one object's content onto other ?[/QUOTE] The problem is aliasing. For example, if any of your data members are pointers then an explicit copy constructor is required to make a deep copy of the object. Otherwise the pointers from two objects will point to … | |
Re: [code] #include <sstream> #include <string> std::string get_file_name(int sequence_number) { std::stringstream out; out<<"today"<< sequence_number <<".txt"; return out.str(); } ... syslog.open(get_file_name(st.wDay)); [/code] Awkward, huh? :) | |
Re: [QUOTE]the "%s%*c" is adding the comma to the string I sent it to[/QUOTE] Yes, because %s is delimited on whitespace. You need to use a scan set to exclude commas along with whitspace: "%[^ \t\n\r\v\f,]%*c". | |
Re: Perhaps: [code] public static void main(String[] a) { int[] test = new int[] {0, 1, 2, 3, 4}; reverse(test); for (int i = 0; i < test.length; i++) System.out.print(test[i] + " "); System.out.println(); } [/code] If all you're doing is testing the reverse method, there's really little need to do … | |
Re: [QUOTE]Some suggestions?[/QUOTE] You've got the right idea, just expand on it: [code] #include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char *argv[]) { if (argc > 1) { FILE *in = fopen(argv[1], "r"); if (in != NULL) { char **lines = NULL; char line[BUFSIZ]; size_t i, n = 0; … | |
Re: [B]>Isn't an fscanf string assignment supposed to work on a char pointer (which is what orig_unit->name is)?[/B] Yes, but pointers aren't magic. You can't simply define a pointer and expect it to point to an infinite amount of usable memory, you must first point it to a block of memory … | |
Re: [QUOTE]most of my friends advise me to go for open source development: use LAMP (linux,apache,mysql,php) combination if i ever develop a web app, or use OpenGL if developing desktop apps in c++ so that they can run on linux apart from windows only, or use java if ever getting thoughts … | |
Re: Are you using Visual C++ Express? atlstr.h is part of the ATL library which only comes with retail versions of Visual Studio. If you're confident enough to do some hacking, you can use the freely available WTL instead (instructions can be found [URL="http://tech.groups.yahoo.com/group/wtl/message/12850"]here[/URL]). Why do you need that header? When … | |
Re: I think you should only work on one ADT library at a time unless you're already experienced with the task (which you clearly are not, no offense). | |
Re: What have you tried? Did you encounter any specific problems? Please elaborate on anything that proves you're not a lazy student looking for a hand out. | |
Re: [B]>The no. of rows varies from 35 to 60.[/B] Then set the size of your arrays to 60. If the number of rows were completely indeterminate (eg. as few as zero and in excess of millions) you would be better served by either a dynamic data structure or an algorithm … | |
Re: [B]>move down the forum list just a bit more.[/B] And then piss off. This is also a help forum, not a "do all of my work for me" forum. | |
Re: [B]>Is there any powerfully software available that automatically create software without and coding knowledge.[/B] Nope. There are tools that generate code and facilitate the process without churning out reams of code, but coding knowledge is still required to take advantage of them. | |
Re: arr looks to be a global array, so you don't need to pass anything, just use it: [code] #include <stdio.h> int arr[12500]; void print(void) { printf("%d\n", arr[0]); } int main(void) { arr[0] = 123; print(); return 0; } [/code] | |
Re: Actually, I'm curious if you've profiled having a, b, and c as non-static members of SIMULATION and verified that it's too slow for your needs. Writing off a viable option because you [i]think[/i] it's not performant isn't the way to go about design. | |
Re: [B]>i meant that why do we need to use data structure?[/B] That's the same question you asked originally. Clearly you're not expressing your question in a way that can be understood, so try rewording it. | |
Re: Image formats typically have header information within the file that defines them. You can look up the format of each image type at [URL="http://www.wotsit.org/"]http://www.wotsit.org/[/URL]. | |
Re: Of course it's possible. I'll offer advice on how to go about a solution if you provide less vague requirements. |
The End.