c++

c++ runtime error? how to solve this and check?

#include<iostream> using namespace std; int main() { int hash, opp, i, j, c = 0; //cout<<"enter hasmat army number and opponent number\n"; while(cin>>hash>>opp) { cout<<opp-hash<<endl; } } time limit for this problem: 3.000 seconds how can i verify and test this condition? i'm submitting this to a compu...

Get all URLs accessed, with response times?

Can anyone help me how to get (or log) all URLs accessed by web browsers in a computer. Together with its response time? Note: visual C++ will be the Programming language to be use and this will run under windows platform. ...

Running app as Windows Service reports COM error 80040154

Hi, I'm trying to convert a normal application to a service. The application uses an installed COM component. When its run as a standalone application, this finds and connects to the COM component, however having converted the app to a service, I get the above error. I understand that this could be related to the fact that in the "env...

ComServer that should return a ComObject

What I am trying to do is transfer an object that has been created on the serverside to the client. I have got it to work well when I using c++ on both server and client side, but I do not get my server to work correct with other languages like .Net, It probably doesn't like the pointers! Does this Serversidecode look correct? Server F...

Pass the current state of a function into another function in C/C++

Is there a way to pass the current state of a function into another function in C/C++? I mean all the parameters and local variables by current state. For example: void funcA (int a, int b) { char c; int d, e; // Do something with the variables. // ... funcB(); // Do something more. } void funcB() { // funcB...

Declare types without implicit conversion in C++

Hi, I want to declare my own numeric types, exactly like unsigned int, but I do not want the types to be implicitly converted. I tried this first: typedef unsigned int firstID; typedef unsigned int secondID; but this is no good as the two types are just synonyms for unsigned int, so are freely interchangable. I'd like this to ...

How can I control the order heap objects are destroyed?

Let's say I have 2 singletons, allocated on the heap, for which no delete is ever called. Let's call them A and B. Is there any way to make sure B will be the first one to be destroyed? I'm assuming the platform may matter on this one: Visual Studio 2005 Professional, Visual C++. Everything was built with cl. ...

Objective-C++ Memory Problem

Hello, I'm having memory woes. I've got a C++ Library (Equalizer from Eyescale) and they use the Traversal Visitor Pattern to allow you to add new functionality to their classes. I've finally figured out how it works, and I've got a Visitor that just returns the properties from one of the objects. (since I don't know how they'r...

How can I retrieve current terminate() handler without changing it?

Here's the problem. My application calls CoCreateInstance() to create a COM object implemented in a third-party DLL. That DLL calls set_terminate() to change the terminate() handler and passes an address of its own terminate() handler there. The initial terminate() handler address is not saved by that library - it doesn't care and simpl...

Detecting debugger on Mac Os X

Hi, I am trying to detect whether my process is being run in a debugger or not and, while in Windows there are many solutions and in Linux i use ptrace(PTRACE_ME,0,0,0) and check its return value, i did not manage to perform the same basic check on Mac Os X. I tried to use the `ptrace(PT_TRACE_ME,0,0,0)` call but it always retu...

Link error in C++ by g++

Please take a look at the program below. Why am I getting an error? #include <stdlib.h> #include <string> #include <string.h> #include <iostream> using namespace std; class serverData { public: static int serverTemp; static int server; }; int main(int argc, char** argv) { string s = "sajad bahmani"; serverData::serve...

QT4 Memory Management

I come from a fairly strong C background, and have a rather solid foundation in C++. More recently I've been working with C# and other higher level languages. A project I'm looking at working on could really benefit from using QT4, but I have some questions on memory management I can't seem to understand. I've read the QT4 documentation ...

C++ Manipulator not being executed

Hi! Well, I'm wondering why endd doesn't seem to execute (though it doesn't generate any error at compilation time). struct dxfDato { dxfDato(int c, string v = 0, int t = 0) { codigo = c; valor = v; tipo = t; } dxfDato() { } int tipo; int codigo; string valor; }; class dxfItem { private: std::ostringstream ss; ...

Iterate Multiple std::vector

I've read here and other places that when iterating a std::vector using indexes you should: std::vector <int> x(20,1); for (std::vector<int>::size_type i = 0; i < x.size(); i++){ x[i]+=3; } But what if you are iterating two vectors of different types: std::vector <int> x(20,1); std::vector <double> y(20,1.0); for (std::vector<int>:...

How do you declare a const array of function pointers?

Firstly, I've got functions like this. void func1(); void func2(); void func3(); Then I create my typedef for the array: void (*FP)(); If I write a normal array of function pointers, it should be something like this: FP array[3] = {&func1, &func2, &func3}; I want to make it a constant array, using const before "FP", but I've got...

Inheritance in Python C++ extension

I have c++ library that need communicate with Python plugged in modules. Communication supposes implementing by Python some callback c++ interface. I have read already about writing extensions, but no idea how to develop inheritance. So something about: C++: class Broadcast { void set(Listener *){... } class Listener { void n...

In C++ how can I prevent a function from being called recursively

I have a function which makes use of memory on the heap and it will go badly wrong if it is called before another instance of the same function has completed. How can I prevent this from happening at compile time? ...

Linker error with pointers

I am trying to build a program to Tolkinize a string (i'm trying to do this with out using the string class - so as to learn more about pointers and how chars work) - I have built a program that i think works (any suggestions would be great!) When i tried to compile the program I get these random errors: Error 1 error LNK2019: unreso...

Why is my MFC DLL deadlocking on a single thread near startup?

Using Visual Studio 2005, the debugger tells me that a deadlock has occurred just after startup of the app I'm writing - I'm well in to WinMain() at this point. The callstack shows that we are in a critical section, while calling AFX_MANAGE_STATE2 (for the 666th time, spookily enough) from within an MFC DLL. This has just started happe...

Pure base class needs to be exported from DLL?

I have two DLLs a.dll and b.dll and in each one I have one class AClass and BClass. I would like to have both AClass and BClass inherit and implement the same interface AbsBase which is a pure abstract class. In each class I set up the #defines for __declspec(dllimport) and __declspect(dllexport). When I'm trying to compile I get this: ...