c++

Vectors with fixed dimension and values (C++)

Hello everybody, I would like to know the best solution in terms of performances for storing vectors/arrays of data (int or double), whose dimension is not available at compile time (it depends on the input from the user) but, once intialized, they will never change their dimensions, neither their values. In other words I was wondering ...

What's a java equivalent for std::round(double)?

In cpp file I have std::round(double) Please can I know the equivalent code in Java Edit: I am already using java.lang.Math.round(double) and getting match in 99% cases. But in some places iam getting mismatch. For example: std::round(4816.5058) = 4816 and Math.round(4816.5058) = 4817 std::round(4466.49996) = 4467 and Math.round(4466...

OpenGL application not picking up 64bit Mesa OpenGL32.dll

I'm trying to get a 64bit OpenGL application running with MESA compiled in 64 bit. When compiling both in 32bit it works perfect putting the opengl32.dll and talloc.dll in the same directory as the executable, however, in 64bit the mesa opengl32.dll driver seems to simply pass on the my hardware driver. If I change the opengl32.dll to a...

Testing for an invalid windows handle: should I compare with 'NULL', '0' or even 'nullptr'?

I'm coming from a background whereby pointers should generally be compared with 'NULL' and integers with '0'. Since I didn't perceive Windows handles to be 'pointers' in the pure sense (being 'handles'), I'd got into the habit of comparing them with 0 rather than 'NULL'. Clearly they're implemented internally as pointers nowadays, but ...

The Important Difference: Overloading vs. Specialization

HI friends , Any one help me The Important Difference: Overloading vs. Specialization in C++ It's important to make sure we have the terms with proof .Thanks in advance The doubt arised "Why Not Specialize Function Templates?" ...

What (not) to do in a constructor

I want to ask you for your best practices regarding constructors in C++. I am not quite sure what I should do in a constructor and what not. Should I only use it for attribute initializations, calling parent constructors etc.? Or might I even put more complex functions into them like reading and parsing configuration data, setting up ex...

Linking Error in Sun Studio 10 under Solaris

I wrote a test program like this: #include <sys/socket.h> int main( void ) { int sock = socket(AF_INET, SOCK_DGRAM, 0); return 0; } And tried to compile it: $ /tool/sunstudio/bin/cc test.c Undefined first referenced symbol in file socket test.o l...

Isn't return value optimization (RVO) a bug?

I maybe asking a dumb question, but I looked at the wikipedia page for RVO here and could not stop wondering if that behavior is wrong. I tried it in my machine and RVO is fully kicked in despite optimization level. What if there was actually something BIG happenning in a constructor? I know it shouldn't, but what if? I can't understand ...

Is there a tool to dump all API inside a dll writen by c/c++ in windows?

Anyone knows such a tool? ...

auto_ptr with swig

Hi, I'm trying to wrap a C++ library which uses auto_ptr. I'm using swig and want to generate python bindings. I'v seen the section of the swig docu on how to use swig with smart pointers here[0]. But I can't get it to work. swig generates code that wants to initialize the auto_ptr using a const reference, but auto_ptr defines the cop...

Returning an iterator in a multi threaded environment, a good idea?

Is it a good idea to return an iterator on a list in an object that is used and shared in a multi threaded environment? class RequestList { public: RequestList::RequestList(); RequestList::~RequestList(); std::list<boost::shared_ptr<Request> >::iterator GetIterator(); int ListSize(); void AddItem(boost::shared_ptr<R...

Operator overloading in c++

struct T { int a; int b; }; class Ptr { public: Ptr(int a, int b) { t_.a = a; t_.b = b; } T* operator->() {return &t_;} T& operator*() {return t_;} private: T t_; }; int main() { Ptr ptr(1, 2); cout << "a = " << ptr->a << " b = " << ptr->b << endl; cout << "a = " ...

address of elements of structure of different types

i want to find address of elements of structure in memory here is my code #include <iostream> using namespace std; struct B{ int k; float t; char s; unsigned int m; long q; double x; unsigned long z; }; int main(){ B b[]={3,4.23,'A',123,123L,23.340,700}; void *t=&b[0]; void *n=&b[0]+7; while(t!=n){ ...

C++ unique_ptr and map

...

Multiple dynamic libraries with the same static variables, how many instances?

Let me explain it with an example: I have a class S, which is static. I have two dynamic libraries A and B that use S. I have an application, that links with A and B, in this application, how many different instances of S are created? All this using C++ and in Ubuntu. Thanks in advance ...

Why its dangerous to use pass by value when function parameter expects an Abstract class object ?

Hi, I read below statements in Addison Wesley FAQs. Beware: passing objects by value can be dangerous in some situations. Often it is better to pass objects by reference-to-const than to pass them by value. For example, pass-by-value won't work if the destination type is an abstract base class and can result in erron...

cannot convert from 'std::string' to 'LPSTR'

As I clould not pass LPCSTR from one function to another (Data get changed) I tried passing it as a string. But later I need to again convert it back to LPSTR. While trying the conversion I am getting the above error: cannot convert from 'std::string' to 'LPSTR' How can I resolve this? ...

String Manipulation Methods giving RunTime Error.

This seems to be giving me a bit of trouble. This method is supposed to generate a random number and assigns it to a char. getline grabs the entire string from the text file and assigns it to foods. y has the purpose of holding the place of where it finds c in the foods string. It will then use that int to erase from the string and prin...

How do I find IIDs for Office outgoing COM interfaces in C++ without MFC or ATL?

I am writing an application that needs to handle events fired by Office - things like 'before print' or 'new file'. From various articles and examples I understand I should use the IConnectionPoint interfaces. I got the ConnectionPointContainer for Word.Application using QueryInterface. Now I want to run FindConnectionPoint, but I have ...

Tool for finding non-virtual destructors

Anyone know of a tool that can find non-virtual destructors of polymorphic base classes? ...