556 Posted Topics
Re: Have you thought of just checking to see if the line is blank before tokenising it? You tokenising routine needs to be robust enough that when it hits a problem it fails in a way you can catch and deal with (normally by just ignoring the line and possibly outputting … | |
Re: Yes a sting is an STL container so you can use all the usual STL algorithms on it like for instance count_if. Also you should use the functions defined in the header local, specifically is rather than the value comparisons [icode]if (paragraph >="A" && paragraph <="Z")[/icode] to check for the … | |
Re: If this is QT then the QT documentation specifically says that you must only inherit from QObject once and QObject is a base class of QWidget. You will have to break the diamond. That might mean having a abstract class that BaseView and ButtonView both inherit from that does no … | |
Re: This sort of thing is not trivial because the different months have different numbers of days and February has different numbers of days in it depending on the year. The are, at least, 2 approaches [list=1]Convert the dates to the number of days past a given epoch date, 1 Jan … | |
Re: Firstly if cpu utilisation is only getting to 70% there is nothing to worry about. All programs are getting all the cpu time they require with time (30% of the available time) left over. A single run of your program however only opens a single file and reads it, if … | |
Re: yes you separate the class definition and the member definitions like this [code] // This is normally in a header file foo.h class foo { public: void DoNothing(); }; [/code] [code] // This is normally in a separate cpp file foo.cpp void foo::DoNothing() { cfee.AddNothing(); } [/code] That way the … | |
Re: My (rustly) recollection from 3-4 years ago is that you need to make a class library project in your solution (I am assuming you're using visual studio) File -> New -> Project... -> Select "CLR" From Tree -> Select "Class library" from the right hand pane. Fill in the name … | |
Re: Interestingly if you had bothered to read the text of that page below the Java applet it tells you exactly how you can calculate the interior angle for a regular polygon and further it links boldly at the top of the page to a page about exterior angles too. | |
Re: [QUOTE=vmanes;1170775][code] for (int index = 0; index <= limit - 1; index++) [/code] is a bit awkward with the [icode] <= limit -1[/icode]. Just use the strictly less than comparison to the actual array size (or limit of valid elements), as in [code] for ( int index = 0; index … | |
Re: You can't pass arrays. You may invoke the constructor with an array in the calling code but what gets passed is a pointer. With-in the context of a function declaration [icode]int a[][/icode] declares a pointer so [icode]IntegerSet::IntegerSet( int a[])[/icode] and [icode]IntegerSet::IntegerSet( int* a)[/icode] are equivilent. In both cases the parameter … | |
Re: [QUOTE=rkp728;1170231]I have included Common_Definitions.h in BC.h and RS.h. #ifndef Common_Definitions_h #define Common_Definitions_h #include "Common_Definitions.h" #endif [/quote]Inclusion protection preprocessor symbols like this are good, but they should go inside the file they are protecting not round every place it is included. Common_Definitions_h should have the structure [code] #ifndef Common_Definitions_h #define Common_Definitions_h … | |
Re: Like the error says you can not use the friend keyword in a managed type (manged C++ has delegates and events to get round that). Why can you just make your MoveRect function a class member? | |
Re: Line 26 [icode]LINKEDLIST *list = malloc(sizeof(list));[/icode] Line 34 - 35 [code]STORE *newVacantStore; newVacantStore = malloc(sizeof(newVacantStore)); newVacantStore = malloc(sizeof(newVacantStore));[/code] In both of these cases you have allocated the size of the pointer not the size of the object pointed to. Pointer is likely to be 4 bytes on a 32bit system … | |
Re: Because C is fairly lax about types and if it has an automatic conversion from the type given to the type required then it will silently do it for you. C knows how to convert float to int so it just happens. This was one of the issues fixed in … | |
Re: You have given your assignment. You have given the code you have. But you have not said what the problem you are having is. Is it an issue with compiler errors? Then post the errors. Is it an issue with the program not performing as expect or desired? Then post … | |
Re: I would question how you are using the vector to store the results. How will you differentiate between results from different functions, or worst results from different functions that take different numbers of parameters? Anyway your storage scheme aside I see 2 possible solutions. You could declare memory mutable. A … | |
Re: When you declare a data member static there is a single copy of that data member used by all instances of the class so a.n and CDummy::n refer to the same variable. CDummy::n is incremented every time a class is constructed and decremented when the class is destroyed. So the … | |
Re: You seem to be treating as a single step, get the return value of a function, what is actually 2 steps [list=1]Return a value from a function [*]Assign that value to a variable [/list] Both have associated efficiencies as follows [b]Return a value from a function[/b] [list]Return by value - … | |
Re: You've missed the braces { } round the 2 lines of code that should be in the inner loop so that the printf statement is only executed once for every iteration of the outer loop. | |
Re: [code] int number = 65; char letter = number; [/code] There are no characters in C only integers with different ranges. A character is no more than a number that is interpreted by the display sub-systems to write pixels on the screen in a forum that you recognise as a … | |
Re: 1. The constructor is for exactly what you have stated "initialize variables or assign dynamic memory". In this case there is no dynamic memory so it is for initialisation of member variables. If you don't implement the constructor then between constructing the object and calling read() your object will contain … | |
Re: The problem is that the parameter [icode]number[/icode] is const (constant) but you are trying to use it to call operator- which is not a const member function. [icode]number[/icode] (const Number &) can not be converted to Number * in order to make the method call in [icode]return number.operator -(*this);[/icode] and … | |
Re: One of the major differences is that floats get promoted to doubles when used as parameters in functions that have no declaration or in the variable parameter list of varidac functions (like printf). So printf never sees a float in the parameter list and does not need to differetiate between … | |
Re: I can't explain why it is working at home, but that is the nature of undefined behaviour, however at line 48 of your code listing you free the array just before you start writing values into it. | |
Re: You are missing the ) at the end of the function parameter list. | |
Re: LPBYTE is a pointer to a BYTE. If you have allocated an array of BYTEs and pointed lpBuf at that allocated array then if you need the size of that buffer you have to store it somewhere. There is no function you can call that will return the size of … | |
Re: It looks to me like what you need is an STL map | |
Re: Note that generating a random number between 1 and N using [icode]rand() % N + 1[/icode] for small N is a poor solution because rand() often has very poor randomness in the low order bits of its return value. [url=http://c-faq.com/lib/randrange.html]read this[/url] Rather than [icode]float pctRoll = (float) (rand() % 1000) … | |
Re: You have only forward declared Vistor in this code snippet so it does compile at line 26 which requires the full declaration of visitor. Assuming this is a mistake that doesn't exists in your actual code and the the missing ; on line 33 is a typo then have you … | |
Re: Just to clarify it is explicitly stated in the C standard that main if returns a value of 0 (or EXIT_SUCCESS) then the program will return a value to the system that indicates the program was successful. Note that is not necessarily 0; if the system in question does not … | |
Re: Not entirely bullet proof since it will interpret my half a shopping list as a date [code] Enter Date String : 1)Fish.2)Chips.3 month : 01 date : 02 year : 2003 [/code] Verifying input involves verifying no additional garbage was input too. | |
Re: You have no ; at the end of your class IntList | |
Re: That is not quite true, when the notify method is called it gets a Subject pointer to some object. You know that object can definitely not be a Subject because Subject is abstract and so can not be instantiated. You have been passed a base class (Subject) pointer to a … | |
Re: Look up the library function strtol, it will convert the digits ignoring leading blank spaces and pass a pointer back to where it finished, which will be the '/', you can then just hop over the '/' to convert the next piece of the number. | |
Re: ships is declared as an array of pointers but on both lines 17 and 23 having selected the array index you dereference the array once with * and once with -> or twice in total. You can dereference a single pointer twice, loose the * on both lines. BTW I … | |
Re: I get this error from your code using gcc BitFlags.h:12: error: ISO C++ prohibits anonymous structs What compiler are you using, this is improtant of course because bitfield behaviour is very much platform dependent. Anyway after naming the struct I get a size of 4 for the struct as you … | |
Re: I have been programming for 20 years and I can say I've missed the absence of a Logical XOR operator where as I know for a fact I would miss the absence of a Bitwise XOR operator. | |
Re: With thanks to Firefox for its ability to highlight the word salary Line 27 of Income Member Function Definitions [icode] salary += s;[/icode] You add the user input value s to salary but salary has not been initialised to anything and contains garbage therefore garbage in = garbage out | |
Re: [QUOTE=Fbody;1163510]3. Line 51 NEVER, EVER, EVER, NEVER recursively call main(). [/QUOTE] Just to expand this statement a little and say that calling main in C++ is expressly forbidden by the standard and some compilers will produce an error. That is one of the many differences between C and C++, calling … | |
Re: Line 11 loanDurationon is defined without giving it an initial value Line 29 the code what would have given loanDurationon its initial value is commented out Line 32 loanDurationon is used in a calculation having nenver been given a value because line 29 is commented out. You need to assign … | |
Re: Almost everywhere you have a loop and access your arrays you have an out of bounds array access, for line declared as bool line[78]; then if it is accessed as line[N] N must conform to the constraint 0 <= N < 78 However [code=c++] void firstline(bool firstline[]) { int y; … | |
Re: Create a structure (or a class) that contains your string and double and then make a vector of those. You can use a normal loop or one of the stl algorithms to perform operations on it. | |
Re: How is y declared? You should perhaps check cin to make sure that no error has occured on it. | |
Re: max_element has 2 forums, one compares elements automatically using the < the other accepts a comparison function as well as the 2 iterators. Therefore either you need to put an operator< method into your structure or you need to provide a comparison function and use the second forum. In this … | |
Re: before trying to implement eliminating lifelines I think you code is in desperate need to refactoring to put common code in functions that can be called. For example: A function that asks the question Parameters: The question The 4 answers The right answer Returns a flag indicating if the question … | |
Re: Always keeping as much precision as possible is definately not a bad option, however there are others. For instance there is no point in keeping 15 decimal places of precision if the value represents a real world item with a fixed quantum of precision, for example cash. I can have … | |
Re: Not for template functions (and classes). A template function are the instructions to the compiler on how to write the function given the parameter types... the template of the function. When the compiler compiles your code and sees a call to a template function it looks up the template function … | |
Re: Why can't you make a new object in the function and return it? Because you are returning const Text&? That is the mistake, you can't implement operator+ returning a reference, it has to return an object so the prototype for your operator+ should be const Text operator+(const Text &) const … | |
Re: I am not seeing anything obviously wrong. When you are cerating the class objects I assume max is not 0, that would cause this behaviour. I would suggest modifying Course::generateClassList, at least temporarily to output max so you can be sure it is good. You have something strange going on … |
The End.