1,358 Posted Topics
Re: [QUOTE=Cross213;1626652]The error I'm getting when debugging (dynamic arrays): Unhandled exception at 0x5bfa782d in Ass4DynamicArrays.exe: 0xC0000005: Access violation writing location 0xabababab.[/QUOTE] You'll have to post some code for anyone to know for sure what's going on, but you appear to be de-referencing an un-initialized pointer. Have you verified that you are … | |
Re: [QUOTE=mike_2000_17;1617776]I can only give you an example in C++, because, to my knowledge, you cannot do compile-time polymorphism in Java. (and anyways, such a question belongs in the Java forum) This is dynamic polymorphism in C++: [CODE] #include <iostream> struct Animal { virtual void doCry() = 0; }; struct Dog … | |
Re: It depends on how you intend to use the vector. In general, however, NO you don't want to specify a vector's size when you declare it. There are very few situations that REQUIRE the vector to be initialized immediately. | |
Re: What do you know about the differences/similarities between the while and do-while loops? | |
Re: What Narue is saying is that you need to elaborate on what your problem is. There are extremely few people here that can magically divine such information. You can get help here, but you need to tell us what your understanding of the issue is before we can even begin … | |
Re: Honestly, this code looks like it may be an overly-explanatory example from a text. The code contains many things that you generally won't see in well-designed/written code. I suggest you read the chapter it's part of a little closer. Here is a highly generalized summary (I want to avoid doing … | |
Re: Click your Start menu/Windows button. Locate the (My) Computer icon/button. Right-Click the icon and select Properties. There is a field in the dialog that appears that tells you. | |
Re: [edit]I know this is a little late but...[/edit] [B]>>I am using Visual Basic C++ 2010 if that helps[/B] Here is your problem. There is no such thing as "Visual Basic C++". It's either Visual Basic or Visual C++. Is your class using the Basic or C++ language that is included … | |
Re: You have to use setw() [B]immediately before[/B] the output you want in the "column".[CODE] //example: //outputStream << setw(width1) << data1 << setw(width2) << data2 ... std::cout << setw(10) << data10 << setw(20) << data20 << //...[/CODE] You are using it after all of your output has already occurred. In that … | |
![]() | Re: [QUOTE=saulocpp;1176085]I'd like to bump this old thread since 2d arrays are a huge problem for the majority of C/C++ programmers. If one needs the array to be dynamic, the nightmare is there. This page has good explanations: [url]http://www.yolinux.com/TUTORIALS/LinuxTutorialC++STL.html[/url] But it never mentions the real problem, that is, the vector resize … |
Re: It's the definition of a template class:[CODE] template <typename T> class Reverser { std::vector<T> stuff; //other member declarations & definitions };[/CODE] This defines a class, called "Reverser", that contains a vector (called "stuff") whose complete type is template/instance dependent. For example, a declaration such as [icode]Reverser<int> revInt;[/icode] would cause Reverser::stuff … | |
Re: First, please use [noparse][code]...CODE tags...[/code][/noparse], they make your code easier to read. See:[CODE]#include <iostream> #include <fstream> using namespace std; int main() { const int SIZE = 81; char input[SIZE]; fstream dataFile; dataFile.open("info.txt", ios::in); dataFile.getline(input,SIZE); system("pause"); return 0; }[/CODE] Second, whenever you are dealing with file streams, you should make sure … | |
Re: I'm not famiiar with boost, I don't use it. Based on what I'm seeing though, you may want to search the documentation for the "boost::tokenizer" type. You probably need to provide an argument to a function somewhere that tells it to use whitespace characters as the tokenization character(s). It could … | |
Re: The "sql" file is probably part of the "behind-the-scenes" stuff that VS does when you build the program. It's probably not actually an sql file, but something that has a filename extension similar to a file type used by SQL CE. Have you actually built the project? You have to … | |
Re: My guess would be 10.0e+6 (10-million). But you're right, that is a strange way to indicate the desired limit... It could also be 10.0e+3 (10,000), but that would generally be 10k. | |
Re: Try to compile and run this:[CODE]#include <fstream> #include <iostream> #include <string> using std::cout; using std::endl; using std::ifstream; using std::ofstream; char const * const fileName = "testFile.txt"; int main() { cout << "This is a file read/write test app...\n" << endl; { //open section 1 ofstream outFile(fileName, std::ios::out | std::ios::trunc); outFile … | |
Re: [B]>>Also, in order to calculate the total sales for a single division, can't you do that in the constructor for the DivisionSale class?[/B] I'm not too sure I agree with this suggestion. From a purely logical standpoint, that makes sense. From a class design standpoint it really doesn't though. That … | |
Re: Arrays and vectors are not the same and are not interchangable. You can not make (in your case) a DAI* point to a vector<DAI>. They are incompatible types. You will need to do this as either strictly vector or strictly array. If you choose array, I suggest that you [URL="http://www.cplusplus.com/doc/tutorial/dynamic/"]read … | |
Re: The C++ language has "compound" operators. The '+=' operator is used to increase the current value of the Left-Hand operand by the value of the Right-Hand operand. Thus, the statements:[CODE] int a = 10; a += 10;[/CODE] Would cause an integer variable, called 'a', to be declared and initialized to … | |
Re: The thing you need to remember is that, unlike some loops in some other languages, in C++ [B]all loops execute on a true condition[/B]. You either need to change the initialized value of "done" to false or remove the "not" ('!') from your condition. | |
Re: You really haven't explained why you want to do that. Is it some sort of misguided attempt at condensation/optimization? You do realize that this will probably create a larger executable because of the stuff that happens "under the hood" inside the class, don't you? | |
Re: So what do you do then if you want to use a string literal, and guarantee that you'll be able to edit it later? Create a constant for it, then use strcpy() (or similar)? I suppose it makes sense, its sort-of considered "best practice" when working with numeric literals (as … | |
Re: You are attempting to re-declare the class in the implementation file (the *.cpp file) instead of simply implementing the member methods. What you need to do is declare it in the header (the *.h file), then implement it in the *.cpp file using the scope-resolution [noparse]operator ( :: ):[/noparse] [CODE]//myClass.h … | |
Re: It's a static member. Only one instance of the member variable exists in the whole program and all instances of the class access the same variable. Additionally, an instance of the class is not required to access it. It can be accessed "directly" from any scope the "test" identifier is … | |
Re: I don't work w/ Qt, so I can't say definitively. Is this a function call that must occur within your main() or is it a function definition? Since you say it's a "line", I'm guessing it's a function call from main() to the actual beginning of your applicaion. Assuming that's … | |
Re: You're also missing a ';' after your prototype on Line 2. Also, while you're at it, you should change your main() to return-type [B]int[/B] and add a [iCODE]return 0;[/iCODE] at the end of the function. This is where the whitespace lecture occurs. Make better use of whitespace and your code … | |
Re: What's confusing you? Do you understand how loops work in general? I have a suspicion about what's confusing you and I suspect that part of your answer will come from answering this question: "Where does the variable/value 'i' come from?". Proper formatting will also help (with some "modernization"):[CODE] #include<iostream> int … | |
![]() | Re: [QUOTE][CODE] 13. day = seconds / 86400; 14. seconds = seconds % 86400; 15. hour = seconds / 3600; 16. hour = hour % 3600; 17. minute = seconds / 60; 18. minute = minute % 60; 19. seconds = seconds % 60;[/CODE][/QUOTE] You're overwriting your hour and minute answers … ![]() |
Re: It's probably an operator precedence issue. The 'dot' operator activates before the "index" operator so you don't have the object yet. Try adding another set of parentheses:[CODE](directedGraph[numSource]).edgeList.push_back(edgeString);[/CODE] | |
Re: You don't want a for loop in this program. You want a while loop. Narue's structure is essentially what you need (although you really should re-write it in a manner that's appropriate for your skill-level). The part of the code that determines whether it's odd or not, and reacts accordingly, … | |
Re: No, Your original code is essentially correct. The problem I see is that the "middle" object is not initialized anywhere, it's a default object. As a result, you are most likely getting garbage values when you call middle.getX() and middle.getY(). What does your "Point" class' default constructor look like? What … | |
Re: Have you written the implementations for the functions? Simply declaring, but forgetting to write, the functions is the most common cause for that type of Linker error. Also, if you have, make sure the *.cpp file that you implemented them in is included in your project. The error basically says … | |
Re: I don't see '7d' in your data anywhere, did you mean '7c'? What if you read it char-by-char until you hit the '|' char? Reading into a struct is basically the same as reading into a variable, you just have some extra syntax related to the member access:[CODE] struct myData … | |
Re: [B]>>But how should the linking look (where should I have my #includes? should i include both declerations and header to the main.cpp? or...? :///)[/B] It is extremely rare that you would have to #include a *.cpp file in another file. You would #include your header file in both *.cpp files:[CODE]//myClass.h … | |
Re: Using quotes ("[I]blah[/I]") instead of angle-brackets (<[I]blah[/I]>) changes the compiler's behavior while it searches for the #included file. Using quotes makes the compiler look in the source file's local directory, then the default include directory. Using angle-brackets makes the compiler go directly to the default include directory and ignore the … | |
Re: I'm afraid I'm not familiar with the term "bit array". One use of individual bits is as a way to make your resource usage more efficient. A bit only has 2 states ON(1) and OFF(0). These states can be used to represent individual yes/no, true/false, etc. values in a more … | |
Re: [QUOTE][CODE]void changePTR(int* p){ int z = 100; int* o = &z; p = o; // p = null // this doesnt work also..?? }[/CODE][/QUOTE] I know you said assume that 'o' is dynamically-allocated, but it's not, and given this example code that's not a reasonable assumption. There are significant logical … | |
| |
Re: Try compiling a "Release" version instead of a "Debug" version. Then make sure you send the files from the "Release" folder instead of the "Debug" folder. They link to different libraries. Because of the library differences, a "Debug" version will only run on a system that has VS installed on … | |
Re: What have you managed to write so far? You'll need [URL="http://www.cplusplus.com/reference/clibrary/cmath/"]the <cmath> header[/URL] to access sin and cos. | |
Re: We're here to help, but you need to help yourself first. We guide to solutions, not hand them out on silver platters. Other than an easy 'A', of what benefit is it to you if we just give it to you? Answer: None. In fact, it's a hindrance to you. … | |
Re: The identifiers "clrscr" and "getch" are found in a header that you haven't included. I'm not going to give you the name of the header because you shouldn't be using it anyway. You'll have to find different ways to clear the screen and get character input. @JasonHippy: get[B]ch[/B] is not … | |
Re: [QUOTE=L7Sqr;1536053]Please use code tags when posting code. To answer your question: Change [icode]char letter;[/icode] to [icode]char letter = 'F';[/icode] That will initialize the letter variable to some known value and ensure that non-random data is not used if nothing else is assigned. In your case, if total is less than … | |
Re: @OP: "It gives a whole bunch of errors." is not a very clear description of your problem. You really should be more specific about the errors. Given what I'm seeing so far, I suspect that there are way too many to post, so I suggest you post just the first … | |
Re: [QUOTE=daviddoria;1535286]I was under the impression that you could completely gaurd anything you wanted with an [icode]#if 0 [/icode]. Apparently this is not the case? I found some code that has opening /* comments but no matching closing */, and the /* seems to comment out the [icode]#endif[/icode], resulting in everything … | |
Re: [QUOTE=kalsi_amandeep;1535267]How long will you take for this??[/QUOTE] I'm sure it was done the same day, or possibly the next. However, considering the fact that this thread is about 2-months old and the OP only has one (1) post, there are 3 possibilities: 1. The OP decided to solve the problem … | |
Re: Your function is declared to return an int. As a result, the decimal portion of the return value is being truncated. | |
Re: There's no need to be a prick about it. Transposition of characters is a subtle-enough error it can be hard to spot. Especially if the person has dyslexia (not that I'm implying they do). @OP: Your window handle is "hgMainWnd", you've transposed the 'h' and the 'g' in your variable … | |
Re: [QUOTE=pritamsingh98;1532516]An abstract class is one whose object cannot be created and inheritance is the property in which super class inherit the property of base class.[/QUOTE] You need to pay closer attention to your terminology. An abstract class is one that cannot be independently instantiated, you have the right basic idea … | |
Re: It looks like a demonstration of arrays as pointers in conjunction with a demonstration of pointer arithmetic. The version that works is a convoluted way of assigning the reference (address) of chr to ptr. |
The End.