1,288 Posted Topics
Re: The function you wrote as follows Other *add(int x, int y) { int z = (x + y); return new Other (z); } is not part of any class. Should it be part of the `Derived` class? Try Other* Derived::add(int x, int y) { int z = (x + y); … | |
Re: Are you really just joking? It's a question I see every so often. If I had to guess, I'd say that because it's not physically possible on every system, and there's no way for the writers of the standard to guarantee that everyone will be using an input method that … | |
Re: There's nothing inside the `for` loop. The for loop ends at that semi-colon on line 10. | |
Re: # Simple version using static libraries # The compiler is presented with a list of source files to compile (i.e. the ones usually named `*.cpp`) For each of those: 1. The preprocessor goes through and handles the #defines, #includes, etc, changing each individual `*.cpp` file into a slightly different `*.cpp` … | |
Re: > my machine does not have the windows.h library. Any suggestions? Are you using Microsoft Windows as your operating system? | |
Re: In C++, you can access each letter of a string (you are using proper C++ string objects, yes? Not a char-pointer) as a char using the [] operator string x; cin >> x; char letter = x[0]; // letter is now the first letter of the string You might then … | |
| |
![]() | Re: This is programming. Thinking about a problem in such a way that the solution lends itself to a programmatic implementation. All the rest is syntax and learning your tools. How would you do this *on paper*? Don't think about how to code it - think about how to solve it. … |
Re: > So it's always incorrent to use a pointer to represent a string? No. It's always correct. It's up to *you* to make sure the pointer is pointing at the right memory to put the **char**s in. | |
Re: As image formats go, doing it yourself is complicated. http://imrannazar.com/Let%27s-Build-a-JPEG-Decoder%3A-Concepts This is the kind of thing most people use existing libraries for. | |
Re: Your question makes no sense. The C object already contains an object of type A. The object of type A gets created when the C object is created. Your code also makes no sense. `a` is an object of type `A`, so you cannot make a pointer-to-C point at it. … | |
Re: `(1/2)` gives the **int** zero. `(3/4)` gives the **int** zero. | |
Re: Somewhere in the windows code is a line like this: #define WM_LBUTTONDOWN 0x0201 So your code `if(WM_LBUTTONDOWN)` is essentially saying: `if(0x0201)` which is essentially `if(true)` You're not checking to see if the left mouse button is currently being clicked - you're simply saying `if(true)` | |
Re: This doesn't make much sense. cin >> userInfo; userInfo = sales[count]; Did you mean this instead? cin >> userInfo; sales[count] = userinfo; | |
Re: > `struct hostent *host;` > > As near as I can tell, this creates a pointer to a memory address holding an instance of the "hostent" struct and refers to it as "host." Not quite. It creates a pointer, named host, pointing at some random piece of memory somewhere. No … | |
Re: What you're asking here is for two different sets of code to be executed at once. You want the timing countdown code to run AT THE SAME TIME as the code waiting for the user to answer the question (or at the very least, interleaved with it so that they … | |
Re: Count the number of letters in each word. Keep track of how many words of each length you find. Look at the record you made and see how many there are of each size. If there are more than one of any size, there are that many words with that … | |
Re: It looks like your program actually has just one array that needs sorting, `struct employ e[5];` This code would sort e[0] and e[1], for example. if (e[0].date < e[1].date) // the sort criterion, currently sorting e[0] and e[1] { // code here to swap e[0] and e[1]; } | |
Re: You need to search rowSubscript values zero to FOUR. You're stopping at three. | |
Re: Step back a bit. C is a general purpose programming language. It specifies almost nothing about your hardware. C is used to program dishwashers and hard drive controllers and DVD players and telephones. C does not know what a keyboard is, or a monitor, or colours, or sounds. None of … | |
Re: I note that you're coding in C, but posting in the C++ forum. If you're meaning to code in C++, C++ provides much safer alternatives to printf and scanf. | |
Re: I have no problem using the 64 bit gcc to build for 32 bit targets. What error messages are you getting? | |
Re: You don't seem to have a **main** function. You are trying to use the array **inventory** without having actually created it. `system("pause")` is hideous and expensive and dangerous and non-portable. http://www.gidnetwork.com/b-61.html | |
Re: To clarify, you want to identify the top three buyers, where each buyer could have bought any amount of any item? That is, if a buyer bought three of item A and two of item B, that buyer has bought five overall? Sounds like you need to examine each element … | |
Re: > In C++ and OOP in general, what do you call a design where a Person class inherits from Head, Arm, Body, Leg classes instead of the other way around? You'd call it badly thought out and very unhelpful. An actual physical person is not a kind of head, or … | |
Re: > but is there any better way to play the audio without installing any software.. C is a general purpose programming language. It specifies almost nothing about your hardware. C is used to program dishwashers and wristwatches and DVD players and telephones. C does not know what a keyboard is, … | |
Re: http://en.wikipedia.org/wiki/Magic_number_%28programming%29 0xfeeefeee is what your system writes into memory that is freed heap memory. This means that something was `delete`d there, and no longer exists, but you're trying to use it as a valid pointer anyway. | |
Re: `while (1)// i think the problem is here` That will loop forever. Change the while loop's condition, or put a `break` in it where you want it to stop looping. | |
Re: `(char *)oldptr` Pretend oldptr is a pointer to a char (a char is one byte, by definition in C)... `- SIZE_T_SIZE` and change its value to point SIZE_T_SIZE bytes earlier... `(size_t *)` and now pretend it's not pointing at a char anymore, instead pretend it's pointing at a size_t type … | |
Re: > Just thinking how physically he point in memory. A pointer is a single number, probably (depending on your system) 4 or 8 bytes. The number is a memory address. That's it. All pointers are the same size. They are all just a single number. There is nothing, absolutlely nothing, … | |
Re: What kind of data is in the file, how is it laid out, and do you want to store it as char, int, float etc? I'm going to guess from your code above that you want it in an array of int. Do you know how many int you will … | |
Re: The for loop only executes ONCE. | |
Re: Yes. If your C compiler is quite modern (C99 or later, you can just use them as normal). If your C compiler is earlier, you must use dynamic memory. Here are examples in C++ and C. **C++** int i; cin >> i; int* array = new int[i]; // an array … | |
Re: If I read out to you 100 numbers, asking you to tell me what the lowest number was when I've finished, how would you do it? In your head, without writing anything down. | |
Re: Welcome to programming. Programming is the art, craft and sometimes science of thinking about problems in such a way that the solution lends itself to a programmatical representation. All the rest is just learning syntax. I'll repeat that more simply; programming is thinking. So you need to think about the … | |
Re: It doesn't know how to get a file named `videofeatures.cpp` Is that file definitely named that, and in te right place? | |
Re: > But then you have a set and get, WARNING: THE FOLLOWING CONTAINS OPINION Why would you have a set and a get? Providing a set and get for everything is a reflex action I seem to see a lot in Java code, but one of the whole points of … | |
Re: Output was: > This program will help you multiply two numbers > Enter the First Number: 3 > Enter the Second Number: 4 > 3 x 412 Works fine for me. Whatever the problem is, it's not the code. | |
Re: derive2 *a; a->show(); This has *not* created an object of type **derive2**. This has created a *pointer* to some random piece of memory, and then tried to use that random piece of memory as if it were an object of type **derive2**. At no point has an object of type … | |
![]() | Re: `ifile.read(bitmap[i][j],sizeof(bitmap));` How much data are you intending to read each time you execute this line? ![]() |
Re: The same way you use it in any function. **main** is just a function | |
Re: It's supposed to do that. It's how the debugger works. You step through functions like that. | |
Re: What input are you typing in? What did you expect to see on the screen? What did you actually see on the screen? | |
Re: Then replace `student a[10];` with a dynamically created array of ten students. | |
Re: class B { public: void getVal(A someObjectOfTypeA) { cout<<"Value of x in the type A object you just passed to me is : "<< someObjectOfTypeA.x <<endl; } }; Alternatively, make the B object permanently aware of an A object. class B { A* aPointerToAnObjectOfTypeA; // constructor B(A* pointerToSomeObjectOfTypeA) { aPointerToAnObjectOfTypeA … | |
Re: The `<<` operator for the `cout` object does *not* take the character data held in a stringstream and output it to screen. No special handling has been written for using the `<<` operator on `cout` with a `stringstream`, so it does the default; outputs the memory location of the object. … | |
Re: If you build with debug symbols included ( -g ) and then run your program under the GNU debugger (gdb) or some other debugger, when it segFaults it'll tell you which line and allow you to check the values of variables to see which one is causing the segFault. | |
Re: A function is C++ is a block of code; you sometimes feed it some parameters, and you sometimes get something back. For example, here's a simple function that adds two numbers and gives back (returns) a number: int addTwoNumbers (int a, int b) { int sum = a+b; return sum; … | |
Re: You will get a much better response if you improve your questions. Here is how you can improve your questions: 1) Show us the code. You already do this. Good. 2) Tell us exactly what input you type in. 3) Tell us what you saw happen, and what you think … |
The End.