2,898 Posted Topics

Member Avatar for aloth

The first observation is that you are using floating-point arithmetic (e.g. 2.6 * M - 0.2). The Zeller algorithm is based on the fact that integer arithmetic is used. In other words, (D / 4.0) is not equal to (D / 4), the former is in floating point arithmetic and …

Member Avatar for mike_2000_17
0
814
Member Avatar for daviddoria

There are indeed special rules about virtual functions, especially when they are inlined. But none would explain what you have observed. Basically, the special rules are about allowing the compiler to by-pass the dynamic binding (vtable lookup) in cases where the object type and thus the virtual function call is …

Member Avatar for mike_2000_17
0
150
Member Avatar for Michael_Tanner

Wow, "delete this;"... I can't begin to tell you how unsafe this is. >>is such a method recommended? Here is my scale in C++: - [B]Desirable[/B] (includes things like RAII, exception-safety, binary compatibility, generic implementations, concept checking, const-correctness, etc.) - [B]Recommended[/B] (includes things like programming-by-contract, independence, abstraction, encapsulation, non-copyable, smart …

Member Avatar for Michael_Tanner
0
150
Member Avatar for Szeth

[URL="http://www.cplusplus.com/reference/iostream/ios/exceptions/"]Here[/URL] is an example of how to tell the fstream to throw an exception if something wrong happened, and how to catch the exception. I guess that is what is required to do. The basic mechanism of exceptions in C++ is with the "throw" "try" and "catch" keywords. Their meaning …

Member Avatar for Szeth
0
221
Member Avatar for az_ez

The bound that you use on the loop is not correct. "length" is the total number of characters in your memory buffer, it is not necessarily the number of characters that was read with fgets from the file. C-style strings are terminated by a null character. So, you should add …

Member Avatar for WaltP
0
135
Member Avatar for Lelly

**PLEASE USE CODE TAGS** it's horrible to read this post. I did manage to spot this: [ICODE]char *p = strtok((char*)s.c_str(), " ");[/ICODE] You cannot use strtok() with an std::string! What is returned by c_str() is a read-only char array. The c_str function returns a constant pointer, but it should return …

Member Avatar for mike_2000_17
0
185
Member Avatar for NV43

If you need the "add" or "union" function to be adding or uniting two sets, then you need to make the function parameter a set: [CODE] template<class T> class set { public: void add(const set<T>& otherSet); void union(const set<T>& otherSet); private: } #include "set.template" //that's weird, btw. [/CODE] And similarly …

Member Avatar for mike_2000_17
0
171
Member Avatar for daviddoria

>>is there anyway I can change this Rgb type to now have the desired stride length? No. All types in C/C++ have a fixed size, that cannot be changed at run-time. No way. If you could change the interface, it would be better to output an iterator object which then …

Member Avatar for mike_2000_17
0
278
Member Avatar for SourabhT

When you pass the object by value (not pointer or reference), a copy of the object is made and used as the parameter. Because the parameter is of type Base, the new object (the copy of the passed object) is of type Base, regardless of the type of the object …

Member Avatar for SourabhT
0
160
Member Avatar for maybnxtseasn

Ok, let me clarify what I think you mean. You would like to have a Log class that does something like this: [CODE] class Log { private: std::ofstream outFile; //.. public: Log(const std::string& filename) : outFile(filename) { /*..*/ }; void recordEntry(const std::string& S1) { //.. outFile << S1; }; void …

Member Avatar for mike_2000_17
0
116
Member Avatar for AODfan
Member Avatar for lochnessmonster

Why not try it and see for yourself: [CODE] #include <iostream> struct Foo { Foo(bool shouldThrow) { if(shouldThrow) { std::cout << "Foo Constructor called, throwing exception..." << std::endl; throw 42; } else { std::cout << "Foo Constructor called, no throwing anything :)" << std::endl; }; }; ~Foo() { std::cout << …

Member Avatar for mike_2000_17
0
99
Member Avatar for sirko

**PLEASE USE CODE TAGS** If you sort the list, using "data.sort()". It will put all the characters in order of their binary representation which you can get from the [URL="http://www.asciitable.com/"]ASCII table[/URL]. You will notice that all numbers are between character #48 and #57. Any character before or after is a …

Member Avatar for sirko
0
246
Member Avatar for jackmaverick1

The _start function is something that the compiler generates. It's actually the first function that starts the program (called the entry-point). Nominally, all this function does is call the main() function. If you do not have a main() function defined anywhere (empty source file or whatever), that is the error …

Member Avatar for jackmaverick1
0
118
Member Avatar for lochnessmonster

Isn't code injection malevolent? I hope you are not one of those despicable hackers. >>I understand this class is VERY POORLY DESIGNED. It's also very incomplete. You are not initializing most of your data members. >>My question is how can i fix this?? The main problem that I see is …

Member Avatar for mike_2000_17
0
107
Member Avatar for Mahkoe

The main reason for using const char* is because it is compatible and linkable with C. Many APIs and other libraries have C interfaces (you use the API via a collection of C-like functions). With these functions, you have no choice but to use types that exist in C, which …

Member Avatar for mike_2000_17
0
1K
Member Avatar for subith86

Whatever it is that is causing this behaviour is not standard. When I tried your program, line 6 would output garbage regardless of line 12 and 14 being commented or not, as expected. It might simply be that your compiler puts "cow" from line 12 temporarily on the stack frame …

Member Avatar for mike_2000_17
0
189
Member Avatar for mitrious

You have no breaking condition in your getline function. The while loop that uses is.get(), when applied to the standard input stream, will never end. Normally, this loop would end when you hit the end-of-file, but cin never reaches that point, it has no end. When there is nothing remaining …

Member Avatar for mitrious
0
356
Member Avatar for LevyDee

The problem is that string is not just an array of characters. First, the array of characters that it does hold is just big enough for the number of characters the string currently has. In this case, you initialize it to " " so it will contain only one character, …

Member Avatar for LevyDee
0
103
Member Avatar for Zvjezdan23

What code do you have so far? What did you try? What is your hold function supposed to do? What is it about this hold function that you don't know how to do or can't seem to make to work? ... >>can anyone help me? We can answer questions or …

Member Avatar for WaltP
0
184
Member Avatar for tomtetlaw

You mean besides reducing the scope of the std::map object? You can swap it to an empty temporary container: [CODE] int main() { std::map<int,int> my_large_map; //... allocate a large number of elements in map. std::map<int,int>().swap(my_large_map); //swap with an empty temporary //at this point my_large_map is empty and the temporary was …

Member Avatar for Rashakil Fol
0
6K
Member Avatar for caut_baia

>>frowns on stackoverflow.com where everybody is posting relevant pieces of code to actually help each other and not vague phrases On SO, almost any post that looks anything like a homework/exam question is closed down by moderators in a matter of minutes. Here we rarely shut-down people, we help people …

Member Avatar for caut_baia
0
372
Member Avatar for Khoanyneosr

This is a classic problem, you have a dangling new-line character on the input stream. You need to call ignore() right after you input the character to clear that dangling new-line. So, at line 31: [CODE] cin >> ans; cin.ignore(); [/CODE]

Member Avatar for VernonDozier
0
592
Member Avatar for C.Cen

If you have more than 1900 of debt at 14%, and you only pay 20 per month, you will never be able to repay your debt, ad infinitum. That's why you get an infinite loop. You should add a check at the start of the loop to see if the …

Member Avatar for C.Cen
0
223
Member Avatar for jackmaverick1
Member Avatar for mike_2000_17
0
117
Member Avatar for SeePlusPlus2

>>Constant pointers mean that once you point to an address, you won't be able to point to anything else? Yes. >>So changing the value of an address that a pointer is pointing to is the only way to change the value of the pointer? The value of a pointer IS …

Member Avatar for SeePlusPlus2
0
232
Member Avatar for PerplexedWon

There are several problems with your code: In Header: Line 61 and 62: You are missing the semi-colon at the end of the line. Line 28: You are missing a semi-colon after } Line 52: There should be a closing bracket }; at the end of the DynStack declaration. And …

Member Avatar for PerplexedWon
0
172
Member Avatar for Zjarek

Try using the fastest and least consuming random number generator: rand48 ([URL="http://www.boost.org/doc/libs/1_46_0/doc/html/boost_random/reference.html#boost_random.reference.generators"]here[/URL] is the list of all options). The one you are using is very memory-hungry and is not the fastest. Sometimes, it might be worth exploring [URL="http://en.wikipedia.org/wiki/Quasi-random_number"]quasi-random number[/URL] generators instead (it is found to be faster and just as …

Member Avatar for Zjarek
0
484
Member Avatar for SWEngineer

It appears that this is just a little compiler flag mismatch. You should follow the instructions [URL="http://tech.groups.yahoo.com/group/OpenCV/message/68131"]here[/URL], and it should work.

Member Avatar for ziggystarman
0
1K
Member Avatar for winrycool1

>>how to use tree and hash tables and linked lists properly using classes. This sounds more like you need a Computer Science textbook. Using trees, heaps, hash tables, self-balancing trees, linked lists, etc. etc., these are computer science topics and they generally differ only on the details when it comes …

Member Avatar for mike_2000_17
0
201
Member Avatar for pandaEater

>>How do you pass an unknown object into a function and save it? It all depends on how "unknown" the object is. There is a big difference between "it could be one of a few different types" and "it could be of absolutely any type that exists or will ever …

Member Avatar for pandaEater
0
4K
Member Avatar for Szeth

>>I'm wondering how to correctly link an array to a class. Well, you can link an array to a class, but that's probably not what you want. What you want is to store an array in a class. This can be done like this: [CODE] class MyClass { int values[10]; …

Member Avatar for Szeth
-2
151
Member Avatar for jkoske

Your declaration of Node should come before your declaration of LList. The compiler doesn't know what Node<T> is because this class is only declared later. When it says "expected initializer before < token", it just means that it didn't recognize "Node" in front of "<T>".

Member Avatar for template<>
0
146
Member Avatar for arjunaw

I think that just an ordinary sleep function would do, no? For example, using boost::thread (I'm not so familiar with native pthread stuff): [CODE] #include <boost/thread/thread.hpp> #include <boost/date_time/posix_time/posix_time.hpp> #include <boost/bind/bind.hpp> #include <iostream> class foo { public: void my_delayed_method() { std::cout << "Hello World!" << std::endl; }; private: boost::thread delay_thread; void …

Member Avatar for arjunaw
0
4K
Member Avatar for WildBamaBoy

Your question is: >>When would it be practical to use a pointer to get a value instead of using the value's name? IF you know the variable's name and have access to it, THEN you can use the variable's name instead and there is no reason to use a pointer …

Member Avatar for WildBamaBoy
0
172
Member Avatar for Razzo1

Use a loop: [CODE] string name; cout << "Enter You're Name: "; while(name.empty()) getline(cin, name); [/CODE]

Member Avatar for mike_2000_17
0
2K
Member Avatar for Labdabeta

Line 210 causes a crash, you should never delete a pointer that you didn't allocate yourself. Especially in this case. The pointer returned by str().c_str() is not a pointer that you can delete (the string object will take care of that). This must be the craziest code I have ever …

Member Avatar for Labdabeta
0
261
Member Avatar for Zjarek

FYI, I launched your program on my home computer (remotely from my office), I will send you the results when I come home later this afternoon.

Member Avatar for Zjarek
0
111
Member Avatar for pseudorandom21

>>Also, there is a lambda function used I would like to remove without adding another function. That's easy. Your Lambda is only calling the isspace function, just replace it with the isspace function. As so: [CODE] sum = std::count_if(left.begin(),left.end(),std::isspace); [/CODE] >>I'm comparing a std::string::difference_type to a std::string::size_type That's ok, it …

Member Avatar for pseudorandom21
0
120
Member Avatar for bleedsgreen33

If you know there is a fixed number of grades/courses, then you actually won't need to check for the newline. If you do want to read until the newline, then you need two steps. First, you read the entire line into a string, and then, you use the string to …

Member Avatar for mike_2000_17
0
133
Member Avatar for Tinee

I think the only problem is that on line 95 and 103, you are using "alp" instead of "alpha". For the rest, it is correct. To some extent, your use of outputting the value of alpha and beta by passing them by reference is correct but not necessary. If you …

Member Avatar for Dingbats
0
226
Member Avatar for FrancisLazo

All your huge switch-statement does is: get a seat selection X -> if X is out-of-range or not available, then ask for another seat selection. -> otherwise, reserve seat X Your C++ code for doing this should be no more than 5-6 lines of code long, if you just follow …

Member Avatar for Red Goose
0
227
Member Avatar for ana_1234

Your stack is a stack of Position objects. You need to push Position objects onto it, not integers. For example, at line 55, you could do this: [CODE] S.push(Position(Start.x -1,Start.y)); [/CODE]

Member Avatar for ana_1234
0
596
Member Avatar for vavazoom

Your creation of the [B] matrix is not correct. First, when making a new matrix, the elements of it are not automatically set to zero, you have to do that. Second, at line 145, I think you have the wrong index for S (it should be j, not i). At …

Member Avatar for mike_2000_17
0
193
Member Avatar for gl7

Just for the record, if you #include <algorithm>, you can replace lines 20 to 38 in template<>'s code with the following: [CODE] TVec::iterator iter = std::find(v.begin(), v.end(), who); //returns the iterator that matches 'who'. if(iter != v.end() ) { v.erase(iter); std::cout << who << " is removed" << std::endl; } …

Member Avatar for gl7
0
155
Member Avatar for cppgangster

Here are a few cases with explanation to make it clear what they are: [CODE] class Hop { public: //could be any scope //this defines a nested class/struct inside Hop, this is a _type_ (not data member). struct NStrct{ int nCount; }; //the above nested type can be used to …

Member Avatar for cppgangster
0
175
Member Avatar for eline83

Your question makes very little sense. I think you have a confused idea of "heap". There are two things that are commonly referred to as a "heap". Formally, a heap is a type of data tree-structure typically used for implementing a priority queue. [URL="http://en.wikipedia.org/wiki/Heap_%28data_structure%29"]Wiki[/URL]. Colloquially, people say "heap-allocated memory" or …

Member Avatar for Ancient Dragon
0
110
Member Avatar for dissectcode

Make search in all your makefiles for the keyword "-Wstrict-prototypes" and remove it. This is a compiler option that is not necessary (i.e. just a warning) and it must be specified literally somewhere in the makefile (or in many makefiles) so you should be able to just remove it. If …

Member Avatar for mike_2000_17
0
241
Member Avatar for tsin

Well. Qt has fairly straight-forward OpenGL support through the QGLWidget, for example this simple [URL="http://www.digitalfanatics.org/projects/qt_tutorial/chapter14.html"]NeHe tutorials in Qt[/URL]. For all the pan/rotate/zoom and select operations, I'm not sure if there are much off-the-shelf components or actions that can do this. Fortunately, this isn't all that hard to implement with OpenGL …

Member Avatar for mike_2000_17
0
186
Member Avatar for lochnessmonster

yes, but I would still recommend making the initial value explicit (as in [ICODE]stinker() : pointer(NULL), age(0) { };[/ICODE]. You are basically asking the person who reads your code to be aware of "value-initialization of POD type means zero-initialization". This is not so common (many people wouldn't even know the …

Member Avatar for vijayan121
0
157

The End.