278 Posted Topics
Re: No one is going to design this for you since you don't show us that you have made any effort at all to think about the problem (other than how to write your question and copy/paste the problem description). You know that you want to use OOP concepts to write … | |
Re: We don't know how your teacher grades.. and what you have learned so far that you could apply. So saying yes it is correct would be a bold statement. But this is indeed a data structure that holds the information listed. However you forgot to initialize the 'city' part of … | |
Re: Are you calling your destructor function explicitly? If so.. you probably shouldn't ;) | |
Re: Are you compiling a 'debug' build? If so, you should get an ASSERT much earlier. Look at your aggiungi function (btw, why are you mixing english and other-language variable/function names? It can become very confusing). In this aggiungi function, why are you creating r2 on the heap(e.g. why are you … | |
Re: I think it's best you try and explain what you are trying to accomplish. At the moment the use of strncpy isn't what it's intended for. It seems to me you have a pollution_day array that you're trying to fill in the set_pollution function... but it's unclear what you want … | |
Re: A much better (C++) solution would be to move away from C-Style arrays and use a container class like 'vector'. This will also allow you to use std algorithms like std::sort to sort the vector | |
Re: Define "Doesn't really work" .. what are your results? What do you expect? | |
Re: [QUOTE=bklearner;1235604]I am not sure how to get the input from the commandline from the user.[/QUOTE] Do you want the user to type something in the console? In that case you get 'get' this input with "cin", it works simmilarly to cout. If you want a user to start your application … | |
Re: stringstreams are a much cleaner solution than dirty C sprintf functions and should definitely be preferred when writing C++ code | |
Re: There definitely is, and it is a big part of the power of C++. What you're looking for are called "templates", there are a lot of references about it on Google but of course if something is unclear you can always post here and someone will explain ;) Edit: You … | |
Re: First of all: Do you understand why there is only one beep and after that never again? Secondly, let's think about your problem. You have an X number of objects(windows) and you want them to perform an action only once. So for each of these objects you can store a … | |
Re: First of all, you should use code tags, no one is going to read through your code like this. Secondly, if you've written this code then the errors should make perfect sense. Did you even check the lines where the errors occur? If so, you need to be more precise … | |
Re: [code] #include<iostream.h> void hi(void) void name(void) int main() { [/code] First of all, you should include <iostream>, not <iostream.h> Secondly, you should tell us in what line the error is.. or at least copy/paste the exact error. But I tried to compile your code and the error is in the … | |
Re: You're confusing compilers and IDE's. Microsoft Visual Studio is an IDE, the code is compiled with the Microsoft C++ compiler. A lot of people have different opinions about IDE's, you're just going to have to try one for yourself and see if you like it, I don't think there is … | |
Re: Your do..while statemen is wrong (so you are getting the error at line 15 I guess, not at 9 where you are also using cin). This indicates that cin itself isn't the problem, but something closely before the line where the error is. A do/while is written like: [code=cpp] do … | |
Re: I don't really understand what your plan is... but if I am correct this should be equivalent and clean: [code=cpp] class PersonClass { public: std::string Name; virtual void GoToWork(){}; // Or GoToJob, whatever suits you }; class LawyerClass : public PersonClass { public: void GoToWork(){ cout << "Going to Court"; … | |
Re: This is the correct (and beautiful) behavior. When you access a member function through a reference or a pointer of a base class, the derived class's function will be called. This allows you for instance to store a container of BaseClass* and store many different DerivedClass objects, without having to … | |
Re: Your result is compiler (option) specific. You're probably compiling with "Optimize for speed (O2)", if you remove this option you will probably not see EQUAL being printed (at least not with my compiler). So try to compile with different options, and print the addresses of a and b ;). In … | |
Re: First of all, use CODE TAGS when you are pasting code! Secondly, you are never calling your function. Finally, look at the loop that you have in your function. You start b at 0, and you want the loop to run only if b is greater than 1 and less … | |
Re: And let's explain why: On line 44, you call searchArray with items and itemA. items and itemA both have different types, but your searchArray expects them to be the same type (both of type 'T'). If you apply firstPerson's fix, 'answer' and 'index' can be of different, or the same … | |
Re: [code=cpp] void main() [/code] Are you sure this is correct? If so.. why? your enemy variable is a local, automatic variable. This means it will be destructed when it goes out of scope(do you know what a scope is?). If you wish to delete the variable at some 'random' point … | |
Re: You should learn the basics of C/C++ before you attempt to make a game cheat/hack. This is simply copy/pasting code and then copy/pasting the error here. Btw, if you read the errors it tells you exactly what to do. | |
Re: You are close actually.. it's really not that horrible. Look at average in the .h file, and then at average in the .cpp file. Now think of it from the compiler perspective, it sees int average( int something ); in the header file, so a function that takes an int … | |
Re: You declare fgetline as a member function of the UTAevent class. Except, when you define it you do not tell the compiler that the definition is part of the UTAevent class: [code=cpp]int fgetline(FILE *fp, char s[], int lim) { // ... } [/code] Look at the other functions declared in … | |
Re: Don't you already do it with 'Equipment' ? You have several options on how to store the Hero object in the vector, you can store it like you store the "String" in Equipment, or you can decide to store a pointer to a Hero object (Hero*) instead.. it depends on … | |
Re: I didn't look through your whole code, but what you do with the thread makes no sense. You create the thread, and then wait for it to complete. Why is this needed? E.g. why did you chose to use a thread rather than just call the function directly. Anyway.. to … | |
Re: You have bigger problems than this... void main() <-- really? char *delim = ";"; <-- You need to learn what a pointer is, and how to use them, what you do here should ring a million alarm bells. The error you are getting is because you are trying to assign … | |
Re: Whenever you call a function, you do not need to include the argument's datatypes. For instance: [code=cpp] // Function that returns nothing and takes 1 int as argument void myFunction( int myInt ) { cout << "Your number: " << myInt << "\n"; } int main() { int myInt = … | |
Re: Well that's all nice and dandy, but no one is going to read through your source if you just ignore the rules this board has (How did you even miss the fact that you should use code tags?). "I need a code in string as much as possible but if … | |
Re: By using your brain and thinking about the problem rather than asking how it is done. As with any problem, try to break it up into smaller, easier pieces. There is a string and you want to count the number of a's... in the real world, how would you do … | |
Re: Encryption is not a matter of "read a book and you can write a quality encryption scheme" there are extensive subjects to the matter. It is always dangerous as a non-encryption-expert to create a encryption scheme, just use an existing encryption library, and don't say it will be less secure … | |
Re: Check your spelling of initRendering function. Also, the drawscene function is spelled with a lower-case s while you try to call it with an upper-case S | |
Re: Can you explain why you want to "hide" the structure from the SetInt and SetString functions? This is a really dirty trick and should hardly ever be necessary in C++... | |
Re: That's not a question, that's "Can someone please do my homework". Which unfortunately no one is going to do for you. So, as with many problems, the first step is: break it up in parts. -> Do you know how to open a file? -> Do you know how to … | |
Re: [QUOTE=gregarion;1183538]Sorry, i pasted the copy i edited. should be while .[/QUOTE] Even that will not compile... Fixing this while loop and running the program gives me the 'expected' 600 output, so I'm not sure what you're doing...(It is impossible to get 400 with CD as input). [code] Enter the roman … | |
Re: You have already done it... Look at how you declare your 'request': [code]Request *request=new Request();[/code] So 'request' is now allocated on the heap.. means you are responsible for cleaning it up (delete request; somewhere in the code). Then, you say.. ok I want 'request' to point to a LoginRequest. [code]LoginRequest … | |
Re: I used boost in a project where I needed regex. It is distributed as a library though so you need to link to it. More info here: [url]http://www.boost.org/doc/libs/release/libs/regex/[/url] With this library, you can put ( ) around the part that you want to return as a match. So e.g.: Message: … | |
Re: You can create a map of "Specific Object" pointers. E.g.: [code=cpp] class CMemoryMap { public: void newObj( const CObject& myObject ) { m_mMemoryMap.insert( std::pair<CObject*, some_data>( &myObject, some_data ) ); } void delObj( const CObject& myObject ) { map_iterator = m_mMemoryMap.find( myObject ); m_mMemoryMap.erase( map_iterator ); } private: map<CObject*, some_data> m_mMemoryMap; … | |
Re: First of all, use CODE TAGS when you post code on this forum (not sure how you missed that with all of the information about it jumping in your eyes). You got the general idea of a mutex right... but there are some things you should note. First of all: … | |
Re: No one is going to do your homework coder2009, but nice try. If you have a problem with these questions.. think further and ask more specific what exactly you don't understand. For example in the first question.. do you know what a static cast is? etc. If you show that … | |
Re: You can't get root2 to output.... are you sure that you are entering values for A, B, C etc. so that Discriminant is 0? As when it's > 0 only Root1 is printed of course. Also have a look at how you check if 'A' is non-zero. What happens if … | |
Re: Think about what an LPCWSTRING is... The example 2 lines what you give does not really make sense to do, it may help if you give some more information on what you want to do. Most importantly: Where does 'name' come from | |
Re: Aren't there any examples in your OS-course book? I had an OS course(outside of my normal curriculum as I study mechanical engineering) too this semester, which included a 'lab' where we were given the task to write a multi threaded assignment. I would suggest using the 'pthread' library, especially in … | |
Re: It's not possible to 'convert' a string to a class with the same name as the value of the string. What you can do is: - Use a switch case, it is much more friendly as 100 if statements. - Create a hash table where you can look up the … | |
Re: This is a typical answer that can be found through 2 seconds of googling. [url]http://www.cplusplus.com/reference/clibrary/cstdlib/system/[/url] Though I generally think calling system() is a bad design, the overhead is massive and mostly there are much better alternatives. | |
Re: There is a thread about clearing buffers as a sticky somewhere. Think about the two differences in C++ with regard to 'assigning a value' and 'comparing two values'. In the do..while loop you want to compare DoItAgain with 'true'. But in your code you assign DoItAgain the value 'true' (By … | |
Re: I don't think this is possible, as malloc is just allocating a block of memory for you, it won't actually put anything in. Could you tell us why you really have to do this? It's often better to ask how to do something than 'why doesn't my implementation work'. | |
Re: So now you expect us to read the whole code line by line, or compile it ourselves to find the error that you could just post in 2 seconds? | |
Re: You have to delete it at a point where you can guarantee that after the delete you won't access it anymore. This can be at the end of an application, in the destructor of a class or just somewhere in a function that prints the variable and is then done … | |
Re: Instead of answering your question(which is not possible with the code you provided) let's take back a step and ask yourself why do you hand over a char*? If, for some obscure reason, it is needed then Dave Sinkula's question should be answered. What .c_str() does, is 'convert' the string … |
The End.