c++

Overriding public virtual functions with private functions in C++

Is there is any reason to make the permissions on an overridden C++ virtual function different from the base class? Is there any danger in doing so? For example: class base { public: virtual int foo(double) = 0; } class child : public base { private: virtual int foo(double); } The C++ faq says that it is a b...

Are global variables bad?

In C/C++, are global variables as bad as my professor thinks they are? ...

Viewing a dynamically-allocated array with the Xcode debugger?

Let's say I have an array in C++: double* velocity = new double[100]; Using the GDB command line, I can view this array with the command: > print *velocity @ 100 and it will print a nicely-formatted list of all the double values inside the array. However, when using the Xcode debugger, the most it will do is treat this as a pointe...

unable to pass a pointer to a function between classes

I'm attempting to pass a pointer to a function that is defined in one class into another class. After much research, I believe my syntax is correct, but I am still getting compiler errors. Here is some code which demonstrates my issue: class Base { public: BaseClass(); virtual ~BaseClass(); }; class Derived : public Base { pu...

C++ SimpleMAPI SendMail always fails?

Hello I am trying to use SimpleMAPI to display a 'write message' dialogue with an attachment on Vista SP1 with either Windows Mail or Thunderbird in a C++ app (Borland C++ Builder 2006). I should be able to use MAPISendMail to do this. I don't fill in a recipient address as I expect the user to do that when the mail client displays a ...

Levenshtein algorithm: How do I meet this text editing requirements?

Hi, I'm using levenshtein algorithm to meet these requirements: When finding a word of N characters, the words to suggest as correction in my dictionary database are: Every dictionary word of N characters that has 1 character of difference with the found word. Example: found word:bearn, dictionary word: bears Every dictionary word ...

What OOP design decision will suit the situation of protocol in client/server app?

I am writing a client/server app in C++ and need to realize simple protocol to sent and receive data correctly. I have a class for server protocol which can convert the message to my format and then convert it again from this format. That what is server-side protocol looks like: class BaseProtocol { protected: int NumberOfBytesInPac...

C/C++ Performance Globals vs Get/Set Methods

I saw this question asking about whether globals are bad. As I thought about the ramifications of it, the only argument I could come up with that they're necessary in some cases might be for performance reasons. But, I'm not really sure about that. So my question is, would using a global be faster than using a get/set method call? G-...

C++ equivalent to Python's doctests?

I think the concept of Python's doctests is brilliant, and as a C++ programmer at a real-time shop, I'm quite jealous. We basically have no unit test capability, which is a severe hindrance. I've seen C++Unit, etc, but is there anything that can extract test cases out of comments like Python's doctests rather than putting them in the c...

C++ Tokenizing using iterators in an eof() cycle

Hi, I'm trying to adapt this answer http://stackoverflow.com/questions/53849/how-do-i-tokenize-a-string-in-c#53921 to my current string problem which involves reading from a file till eof. from this source file: Fix grammatical or spelling errors Clarify meaning without changing it Correct minor mistakes I want to create a vect...

Why did I get a Segmentation Fault with a map insert

I want to insert a pair< string, vector<float> > into a map, first it works, but after several loops, it cannot insert any more and throw me a segmentation fault. Can anybody give a possible reason? Btw: I first read a file and generate the map (about 200,000 elements) and I read another file and update the old map. the error occurs w...

How do I alter this tokenization process to work on a text file with multiple lines?

Hi; I'm working this source code: #include <string> #include <vector> #include <iostream> #include <istream> #include <ostream> #include <iterator> #include <sstream> #include <algorithm> int main() { std::string str = "The quick brown fox"; // construct a stream from the string std::stringstream strstr(str); // use stream it...

Programmatically access CPU fan on a laptop? (Windows)

Is there a Windows standard way to do things such as "start fan", "decrease speed" or the like, from C/C++? I have a suspicion it might be ACPI, but I am a frail mortal and cannot read that kind of documentation. Edit: e.g. Windows 7 lets you select in your power plan options such as "passive cooling" (only when things get hot?) vs. "a...

round() for float in C++

I need a simple floating point rounding function, thus: double round(double); round(0.1) = 0 round(-0.1) = 0 round(-0.9) = -1 I can find ceil() and floor() in the math.h - but not round(). Is it present in the standard C++ library under another name, or is it missing?? ...

Confusing gprof output

I ran gprof on a C++ program that took 16.637s, according to time(), and I got this for the first line of output: % cumulative self self total time seconds seconds calls s/call s/call name 31.07 0.32 0.32 5498021 0.00 0.00 [whatever] Why does it list 31.07% of time if ...

Pros and Cons of different string types in C++

Sorry to start another of those unanswerable questions on SO, but I'm just curious as to the pros and cons of all the different string types in C++. My particular question is between MFC's CStrings and std::string (since I'm doing Windows only software), but this would extend to any of the string formats in C++. What do you all thing i...

Loading a text file into a vector <string>

I want to load separately the words on a text file like text.txt Hi this is a text file with many words I don't know how many into a vector<string> how do I go about it? ...

Keys / Values Functionality to Iterators in C++

Hi, I know this questions has come up in various guises before, but this is slightly different. I have a class which contains a std::map. Although I wish to use the map for other purposes inside the class, externally I want to expose an iterator adapter to just the values inside the map (ie the second item in the std::pair). For examp...

How do I find a computer's IP address?

I am writing a program in C++ which uses network sockets. I need to find out what the computer's IP address is, so I can display it to the user. The program must run on Windows and Linux. I have heard somewhere that a computer can have multiple IP addresses. I want the one that other programs on different computers can use to connect to...

How to call an external program with parameters?

I would like to call a windows program within my code with parameters determined within the code itself. I'm not looking to call an outside function or method, but an actual .exe or batch/script file within the WinXP environment. C or C++ would be the preferred language but if this is more easily done in any other language let me know ...