c++

Does new() allocate memory for the functions of a class also?

class Animal { public: int a; double d; int f(){ return 25;} }; Suppose for the code above, I try to initialize an object, by saying new Animal(), does this new() also allocate memory for the function f()? In other words, what is the difference in memory allocation terms if I had this class instead and did a new Animal() ? : c...

Why global and static variables are initialized to their default values?

In C/C++ why globals and static variables are initialized to default values.. why not leave it with just garbage values ? Any special reasons for this ? ...

Maintaining a std::set<boost::shared_ptr>

I'm writing a game and an accompanying engine in C++. The engine relies heavily on automation using a simple embedded scripting language. Scripts can create object classes, define event listeners on them, and produce instances from them. At present, an instance must be bound to a script-global identifier in order to preserve its existenc...

Decreasing performance writing large binary file

Hi all In one of our softwares we are creating records and storing them in a binary file. Once the writing operation is completed we read back this binary file. The issue is if this binary file is less than 100 MB then its performance is good enough, but once this file grows larger its performance is hit. So, I thought of splitting t...

How to pass a string literal to a function which takes const std::wstring&

Hi I have a function which takes const std::wstring& font_family, i.e. Font Font::CreateFont(const std::wstring& font_family){ ... } By question is how can I call that funcion by passing a string literal (e.g monospace)? I tried CreateFont("monospace"); CreateFont("std::wstring("monospace") ); Both does not compile. Any one hav...

Basic C++ program crashes VS 2008

I'm following this tutorial on wrapping a .lib in a C++ DLL. Right after I use the VS wizard to generate a Win32 DLL project, everything compiles just fine. Then, following the tutorial, I substitute this VS-generated code: DEMODLL_API int fnDemoDll(void) { return 42; } for this code: DEMODLL_API int fnDemoDll(int a,int b) { ...

How to make a PInvoke friendly native-API?

How to make a native API to be PInvoke friendly? there are some tips on how to modify native-programs to be used with P/Invoke here. But before I even write a native programs, what are the things I should look out to make my programs/library PInvoke friendly? using C or C++ are fine. update: if I write a C API, what are the things I h...

Embedded Assembly Files in Visual Studio

I'll make this short and to the point. The _asm block has been completely stripped when creating 64 bit code in Visual Studio. My question is, where can I find some information on how to use assembly in some code that I can call from my project. Like an assembly file I suppose that has some "optimized" function in which I can call direct...

C++ syntax to call templated inner class static member function?

I have some template code which compiles fine in VC9 (Microsoft Visual C++ 2008) but won't compile in GCC 4.2 (on Mac). I'm wondering if there's some syntactical magic that I'm missing. Below I have a stripped-down example which demonstrates my error. Sorry if this example seems meaningless, I removed as much as I could to isolate thi...

C++: making shallow copy of an object a) syntax b) do i need to delete it

hello gurus, I have a class MyClassA. In its constructur, I am passing the pointer to instance of class B. I have some very basic questions related to this. (1) First thing , is the following code correct? ( the code that makes a shallow copy and the code in methodA()) MyClassA::MyClassA(B *b){ this.b = b; } void MyClassA::metho...

sending file by C++

I want to send a file in C++ over network (for a chat program) what should I do? ...

Creating Java object with boost::posix_time::ptime serialized XML representation

Hello, I have following XML generated by serializing a boost::posix_time::ptime structure. I want to create a Java Date object with this XML. <timeStamp class_id="0" tracking_level="0" version="0"> <ptime_date class_id="1" tracking_level="0" version="0"> <date>20100119</date> </ptime_date> <ptime_time_duration class...

PDB file from different versions of Visual Studio

I have an old DLL file which was built with VC++ 6. Now I need to investigate the dump file but I don't have its PDB available. The stacktrace reported by WinDbg is also inaccurate. Is it possible to rebuild the project with later versions of Visual Studio i.e. 2003, 2005, 2008, have the PDB generated, and use this to map addresses to ...

g++ and file read, weird behaviour with xcode/snow leopard

Hi, I am writing a program that reads a file, whose first two lines are: Field of space: 0.4 226981 20 Then I want to pass 226981 and 20 to integer variables. So I do: ifstream vfile(file_name, ios::in); vfile.getline(header,FILENAME); // Read the header-line vfile >> nTot >> file_size; If I compile the program wit...

How functions are resolved by compiler?

How it is determined whether the below call is bound at compile time or at runtime? object.member_fn;//object is either base class or derived class object p->member_fn;//p is either base class or derived class pointer EDITED: #include <iostream> using namespace std; class Base { public: Base(){ cout<<"Constructor: Ba...

MacOSX: How to collect dependencies into a local bundle?

I am creating a plugin application (dylib) that depends on several other libraries. These other libraries are installed on my system, but are not guaranteed to be installed on any user's system. So I need to find a way bundle the dependencies along with my application. I found that I can use otool to list or change the paths to other dy...

C++ library/framework,API for Mixture models in machine learning

I want to use Gaussian mixture models for data clustering ( using an expectation maximization (EM) algorithm, which assigns posterior probabilities to each component density with respect to each observation ) . Is there a c++ library which has Gaussian mixture models implemented alongwith sample dataset and examples? ...

What's the difference between ON_NOTIFY, ON_CONTROL, ON_CONTROL_REFLECT?

I always struggle to keep all these macros straight in my head. Is there an easy way to remember them, and which to use in a given scenario? Specifically, does one of these allow a dialog to intercept/detect messages to child control windows? e.g Can the dialog register an interest when IDC_MY_CONTROL gets a WM_PAINT message? ...

Use Boost.Signal instead of Qt's signals? Do without moc?

I know they can be used together, but I'm wondering whether it's possible to replace Qt's signals and slots mechanism with Boost.Signal in the Qt parts of the program (widgets and such). Anyone ever try it? Any gotchas? Assuming I don't use any other MOC features and replace signals/slots with boost.signal, is it possible to do without...

C++ certification

Is there any industry standard C++ certification exam, like SCJP ? ...