c++

C++ -- How to prevent an object from being allocating on stack?

Hello all, you have a class A, where you set ctor to be private, so a client can't call A a; to create obj on stack. But someday another developer adds a new ctor: A(int) and try to call "A a(1);" inside main(). So this will create a obj on stack. How do you prevent that? Here is my solution but I don't know whether or not it mak...

Calculate Area and Circumference of a Circle with input in C++

Hello again, I am writing a code for class and I thought I hat it all down pat. However, can not get any feedback from the input when I compile this on XCode. My code is as follows: /* James George Hayek PCCC Assignment 2 Prof Siegel This program will calculate the area and circumference of a circle. */ #include <iostream> #in...

Programming language suggestion for Windows app to connect to Sybase database

I am writing a Windows application that will connect to a Sybase database through an ODBC connection. It will dynamically create a SQL statement based off of selections by the user in the GUI. It needs to be fast (1M+ records sometimes) and have the ability to export to Excel, or some other reporting tool (graphs, etc) What would be th...

Speed of finite state machines - OO vs procedural

Hey all, I am designing a program that will accept from input a series of tokens and feed them to a finite state machine which I have designed. I have designed a test finite state machine in object-oriented style, with structs for the machine itself and transitions, etc. but the application I am writing is one where speed is very importa...

Boost::process async_wait process

Hi all I am creating a program and I'm doing the most possible asynchronously. I need to run a program and when this program finishes it calls a callback function. I found a version of boost::process and decided to use, but it seems that there is the example but could not find the implementation in the source that I downloaded, could s...

What does string::npos mean

What does the statement string::npos mean here found=str.find(str2); if (found!=string::npos) cout << "first 'needle' found at: " << int(found) << endl; ...

Operator error in template

I am trying to create a "value" template class, where additional properties can be assign to it easily. Properties are stored in std::map<std::string, std::string>, and operator[] has been overloaded to provide quick access to them. #if ! defined __VALUE_H__ #define __VALUE_H__ #include <string> #include <map> namespace Algorithm { ...

Constructor help with const C-string array

Hi, I have a simple class Name: class Name { private: char nameStr[30]; public: Name(const char * = ""); char * getName() const; void print() const; }; I am having two problems, which are just a bit difficult for me wrap my head around. The constructor is supposed to take an argument of const char * and copy that ...

Is there a portable equivalent of gcc's __attribute__ (pure)?

I'm writing some code where there are a bunch of simple pure functions that get called a lot. It's perfectly safe if these functions get get optimized to be called less often. Currently I am using gcc as my compiler and I'm wondering if there is a portable way of doing: int foo(int) __attribute__ ((pure)) Info about the pure keyword ...

Generating Vector of Random Number (of Size M) from -K to K in C++

Is there a fast way to do that? ...

c++ string in C struct, is it illegal?

struct run_male_walker_struct { string male_user_name; string show_name; }; typedef struct run_male_walker_struct run_male_walker_struct_t; in another function: run_male_walker_struct_t *p = malloc(sizeof(struct run_male_walker_struct)); question, is it illegal? As the string is a class, it's size can't be determined...

Getting to know the caller is from which DLLs

Currently, I have a C++ exe project, which dynamic load N DLLs. Those DLLs will perform calling to the functions which is re-inside exe project. Now, within my exe project, I wish to know the callers are coming from which DLLs. Is it possible to do so using any available Windows API? ...

Checking if a directory exist in Unix (system call)

Hello, I am not able to found a solution to my problem online. I would like to call a function in Unix, pass in the path of a directory, and know if it exists. opendir() returns an error if a directory does not exists, but my goal is not to actually open, check the error, close it if no error, but rather just check if a file is a direc...

Defining a string with no null terminating char(\0) at the end

What are various ways in C/C++ to define a string with no null terminating char(\0) at the end? EDIT: I am interested in character arrays only and not in STL string. ...

Why does my function pointer code run with no errors?

I have this: typedef void (*funcptr) (void); int main(){ funcptr(); //this can compile and run with no error . WHAT DOES IT MEAN? WHY NO ERRORS? } ...

Do boost::shared_ptr<T> and boost::shared_ptr<const T> share the reference count?

There are several interesting questions on pitfalls with boost::shared_ptrs. In one of them, there is the useful tip to avoid pointing boost::shared_ptr<Base> and boost::shared_ptr<Derived> to the same object of type Derived since they use different reference counts and might destroy the object prematurely. My question: Is it safe to ha...

How to differentiate Whether a Drive or NetWork Drive, on RightClick

When I Rightclick on a Shell Drive I want to differentiate whether the Drive is a Normal Drive or a Network Drive. I hope we can do this using Initialize(LPCITEMIDLIST, LPDATAOBJECT, HKEY) method but unsure which parameter to use. ...

Asterisk cross platform compilation

I am trying to compile asterisk from windows using netbeans c/c++ IDE. As i want to add some functionality into the existing code. when i am running the configure file i got the following errors cygwin warning: MS-DOS style path detected: .\configure Preferred POSIX equivalent is: ./configure CYGWIN environment variable option "n...

A doubt about Exceptions

I was just playing around with exceptions in the visual studio and with the above code I was expecting that since my exception specification doesnt mention anything the bad_exception should have been thrown. But what actually happens is the exception gets caught by the apprpriate handler. Why so? Am i missing some setting or something in...

QGridlayout changes height of row

I have a problem with a QGridLayout. One row of my layout contains an element (QProgressbar) that is normaly hidden. When there is some progress to report i call show on it. The problem is that when i call show on the QProgressbar the row above the row containing it will be slightly resized in height (1-3 px). So the whole layout does a ...