2,898 Posted Topics
Re: In the constructor, you shouldn't have "int boar..", repeating the type (int) will declare a new variable called "board" that is local to the constructor. so you are initializing a local array board and never initializing the data member "board". So that is why the private data member "board" remains … | |
Re: From looking at the original problem, it may be required, and it makes the "drawing vertically" problem a bit easier, to sort from most often occurring letter to least occurring letter. But as jonsca said you can do it without sorting too. | |
Re: One big problem: [CODE] // Variables required for the function ...and all the code that follows... [/CODE] All those variables you declare are not initialized to any value, this can be dangerous and I would suspect (or know) that your compiler is probably complaining a lot when you attempt or … | |
Re: Well, the brute force method for this is to just make the list of all games that are to be played (as you have there) for x number of teams (btw. the number of teams have to be even for this to work, otherwise, every day there is one team … | |
Re: First, INFINITY comes up because of a divide-by-zero, so check that you don't have a 0 divisor before dividing. NOTE: your random function is really unnecessarily complicated. Line 59 should read: "b[i] = b[i] + (A[i][j] * s[j]);" notice the index "j" for the vector s. Line 94 should read: … | |
Re: I see nothing wrong with that. Maybe if you are going to use this trick a lot, either you may want to have global (or namespaced) identifiers (enums) for your units or you may want to attach the unit to the type of the parameters, this way you don't have … | |
Re: Did you check the token string you get that should contain the balance? I would suspect it turns out to be "0" instead of "80" or errorneous. 3.35323e-307 is a really weird number, but it is a number very close to 0, so it might actually read 0 and not … | |
Re: Well as the compiler says, and he is always right, call to move() is ambiguous. [CODE] if(a==1) obj.move(); //What is the difference between this. else if(a==0) obj.move(); //And that. [/CODE] You need a final override method when you have a dreaded-diamond. move() needs to be implemented in the watercar class, … | |
Re: Are you sure that your sort algorithm is doing what you want? or what is asked? In my understanding, you have to take each pair (x,y) and sort them from lowest row-index (which is x) to highest and if x's are the same then put the pair with the lowest … | |
Re: You should clarify what you mean either "read from an array" or "write into an array"... I'm not sure which one you mean. If you have a string that contains all questions.. then I guess you have to do a for-loop for each character until you hit a '?' character … | |
Re: They are both correct. Both just make sure that you use the sizeof() function to determine the size of you buffer, like: char buffer[1024]; size_t bufferSize = 1024*sizeof(char); //NOT just 1024. From [url]www.cplusplus.com:[/url] void * memset ( void * ptr, int value, size_t num ); Fill block of memory: Sets … | |
Re: I remember, as I was looking into making an ABI for my projects, that there is very loose standards about how a compiler is allowed to lay out the variables of different scopes. From what I recall, public data members are required to be ordered in memory as they are … | |
Re: Man.. you have some twisted questions.. I'm not sure of the rules. What I understand is, you mean what constructors will allow the compiler to build some constant values as literals. As in: [CODE] One some_variable(1,2); //would act like: int some_int(1); //in the sense that the constructor is not called … | |
Re: Optimization by the compiler is always a nebulous matter because it is really up to the compiler to do the optimizations it deems necessary or not. One solution is to use scopes within your functions (I mean "{ ..code.. }" just like that). This way the compiler can more easily … | |
Re: Please wrap code in tags next time.. Why do you need to get the numbers a string first? Just use an array of int for "names" and get them from cin directly as integers, just like you do with "input". so change the type of "names" to "int names[5];" and … | |
Re: Look at [URL="http://www.cplusplus.com/reference/iostream/ostream/seekp/"]this[/URL]. When you are about to write the value of No_atoms (which I guess is a dummy value at first), call tellp() before writing the dummy value and save the location value it returns. Afterwards, when you have a real value of No_atoms, use seekp() to get back … | |
Re: I'm not sure there is syntaxically correct way provided by C++ (or C legacy stuff), but here is one slightly dirty way to get it done: [CODE] memmove(variable + 6, "YouMary", 7 * sizeof(char)); [/CODE] | |
Re: Yet another alternative.. maybe a bit of overkill or too advanced but if you want to implement this is the future again in a robust manner, you should know this thing you are probably trying to do here is called a "singleton", at least from reading between the lines of … | |
Re: @thelamb, any class that has at least one pure virtual method in its declaration or in any of its ancestors (base classes) that has not be overriden (provided an implementation for) is by definition an "Abstract Class". So I don't know what you mean by "complete abstract class" (I guess … | |
Re: Well look at [URL="http://beta.boost.org/doc/libs/1_43_0/libs/preprocessor/doc/index.html"]Boost::Preprocessor[/URL], if there isn't a way to do this with that library, there is no way to do it period. There is BOOST_PP_STRINGIFY which takes a non-literal string like just abc and turns it into a literal string "abc". There might be other things of that flavour … | |
Re: Well, at least with the current draft of C++0x, as implemented by the newest linux g++ compiler (with flag "-std=c++0x"), all of the following work, but not the _exact_ syntax you have up there. [CODE] Temp t = {'a','b'}; Final obj(t); Final obj2({'a','b'}); Final obj3(Temp({'a','b'})); [/CODE] | |
Re: Simple Google search gives [URL="http://www.parashift.com/c++-faq-lite/operator-overloading.html"]this[/URL]. | |
Re: I guess you could start from a tutorial example (from msdn or somewhere else), just copy/paste the code and start tweaking it, that's the easiest way. Then I guess you will need two programs, one that sends (or at least initializes the communication) and one that receives. Or what you … | |
Re: 1. Initially the constructor has its own allocated memory (which sizeof(string*) + 2*sizeof(int), for arr (pointer to string) and numAllocated and numUsed (two integers)), then the constructor itself allocates memory for two string objects (size = 2*sizeof(string)). I cannot tell you how big each of there are because that is … | |
Re: You should always test, after you use dynamic_cast, whether the returned pointer is NULL. In this case it shouldn't though, so back to square one. This is not polymorphism (at least not what it usually refers to), you're not supposed to have to perform a dynamic_cast just to call a … | |
Re: I'm not sure I understand what you want to accomplish exactly, but consider first using a shell file (.sh in Unix/Linux or .bat in win console). I'm not sure how you should write it because I don't understand the goal, but I'm pretty sure that will be enough. If you … | |
Re: I'm not sure how glutBitmapCharacter works, and these results are very weird indeed. Somehow it must treat each letter as an unclippable entity, which is weird. I used to render text to the screen the old-school way and it works without problem. That is, create 256 display lists, each rendering … | |
Re: Your call to "cin >> phrase" will by default copy the string before the first space character. Just replace it with "cin.getline(phrase,1024,'\n');" and it will work. | |
Re: Use a mutex to protect the access to vector. Mutexes are your best friends in multi-threading. A mutex (short for "mutual exclusion") is a thing that is supported by all multi-threading-capable operating systems (the API functions to use may change depending on your OS). What it does is that it … | |
Re: Well there is a very simple example (in C++): [CODE] //create an interface class for a visible objects. class VisibleObject { public: virtual void render() = 0; //pure virtual function that renders the object. }; class Box : public VisibleObject { private: .. public: void render(); //implement this such that … | |
Re: The purpose of a game engine is to facilitate development of one game, then another, then another, etc. (typically a real game is made of 80-90% game-engine code and the rest is the actual game logic, then you have the artistic part, all the 3D models and animations and everything). … | |
Re: You can do a C-style cast (although the compiler will complain) or a reinterpret_cast of the pointer to one with no const restriction. Or as Agni said, just make it mutable. One thing that ticks me though... you say "I have a const-correct method".. well putting "const" at the end … | |
Re: I agree with Stu, you need to post some sign of an effort. Just a start-up idea, use a function (method) to compute the square-of-the-distance between two points (as in a method of class "point"), and you can pretty much use it for all the other methods. @StuXYZ: you should … | |
Re: you're not outputting values f[0] and f[1] before entering the loop. | |
Re: Well \ is a special character. C++ still caries the remnants of C formatted strings, for good reason. So "\\" actually means the single character "\" and "\" or '' is an error. This is because you use \ to enter special characters like '\t' for tab, '\n' for newline, … | |
Re: @coolzinthis this is pretty straight-forward: [CODE] #include <iostream> #include <fstream> #include <string> #include <iomanip> using namespace std; struct Person { string first; int votes; }; int computeTotalVotes(Person* candidates, int count) { if(candidates == NULL) return 0; int sum = 0; for(int i = 0; i < count; i++) sum += … | |
Re: Well, I have more than 12 years of experience in OOP programming and I started as a teen with 3D game programming (now doing more multi-body dynamics simulation, robotics control software and artificial intelligence). I jumped right into OpenGL from the start and painfully rammed through it all. I recommend … | |
Re: @Agin: I think using generic algorithms goes against the purpose of the exercise.. First, a simple trick is to use a magic number like 0 or MAX_INTEGER or something to mark the already matched values as invalid, then check that a number is valid before looping for matches. Second, the … | |
Re: I don't understand how "gradez = grade[] + 1;" is supposed to "try to match what letter grade the user typed". This makes absolutely no sense to me! well, doing "gradez++;" will effectively turn an 'A' into a 'B' and so on. I guess that line was mistyped on this … | |
Re: cin is a buffer, it needs to flush, just like cout. There is no guarantee that cin will flush every time you press a key but it is guaranteed that it will flush when you hit enter (just like cout is guaranteed to flush when you write std::endl or "\n"). … | |
Re: Wow... your prof. seems to be a d'bag. Not to mention that this is probably the worst possible way to implement a sparse matrix class. And it doesn't seem like your prof has much of an idea about C++ programming. Anyways, the explanation is very vague, but from what I … | |
Re: the copy() function will try and increment the iterator on std::cin until it finds this null istream_iterator (which I doubt is a correct use, but I'm not so familiar with this class). The problem is that std::cin is special in the sense that every time to increment the iterator it … | |
Re: First of all, you need some kind of GUI for this, cin / cout won't be good enough for sure (or a least a lot of trouble). So figure out what you want to use first (Qt, MFC, SDL, whatever..), then you can start to solve that problem. Second, I'm … | |
Re: First of all, inventory should be initialized to contain at least one element for case A (otherwise inventory.begin() is pointing nowhere) and at least two elements for case B,C,D. Then, you have to understand that an iterator is essentially a pointer (not exactly, but it behaves like one), so setting … | |
Re: I think C++ can be hard at first.. a good way to ease into, if you already have some experience with C or other simple procedural languages, is to just keep programming in C but compile in C++ and slowly change you habits from printf to std::cout, from malloc to … | |
Re: You should find out where this error occurs: Is it before writing the first chunk? -something wrong with init. Is it right when you switch to second chunk? -something wrong with the switch. Is there anything special about the point at which the error occurs (middle of a chunk or … | |
Re: This site was not mentioned yet, but I like it a lot for all the small details you might overlook while coding but that often are hugely important: [URL="http://www.parashift.com/c++-faq-lite/"]http://www.parashift.com/c++-faq-lite/[/URL] It nicely written and cover a plethora of issues from very simple to very complex. | |
Re: Well from what I know if you use shared libs (as it is stated there) than don't expect your library to be completely statically linked.. it is not dependent on how you compile or link your code but how the libraries you use are made. As simple as that. A … |
The End.