c++

Array index out of bound in C

Why does C differentiates in case of array index out of bound #include <stdio.h> int main() { int a[10]; a[3]=4; a[11]=3;//does not give segmentation fault a[25]=4;//does not give segmentation fault a[20000]=3; //gives segmentation fault return 0; } I understand that it's trying to access memory allocated to pr...

Modifying vertex properties in a Boost::Graph

I am trying to figure out how to use boost::graph to store some information. However, there is information I want tied to each vertex. Staring at the documentation for the library reveals either(a)badly written documentation, or (b), I'm obviously not as good at C++ as I thought. Pick two. I am looking for either a tutorial on assigning...

Relational Operator Implementation Dilemma

I'm in the process of designing several classes that need to support operators !=, >, <=, and >=. These operators will be implemented in terms of operators == and <. At this stage, I need to make a choice between inheritance¹ and forcing my consumers to use std::rel_ops² "manually". [1] Inheritance (possible implementation): template<...

Is there a best practice for accessing C++ native COM functions to interop from C#

For example, if I have 100 C++ methods (basically a native library) that interacts with a core window component. I want to basically make a wrapper for these c++ methods in C#, so all my new hire employees can use that instead of C++, etc. the C++ code is legacy and scares me, so I Want to deal with it just once. Is the approach here, ...

How is dynamic memory managed in std::vector?

How does std::vector implement the management of the changing number of elements: Does it use realloc() function, or does it use a linked list? Thanks. ...

Static instance of MSXML2::IXMLDOMDocument2* becoming invaild

I have a C++ dll (x.dll) which exports a class that uses a static instance of MSXML2::IXMLDOMDocument2*. In X.dll wrapper.h class EXPORTEDCLASS wrapper { wrapper(); public: // Some accessor methods. private: PIMPL* pImpl; }; wrapper.cpp class PIMPL { public: PIMPL(); static MSXML2::IXMLDOMDocumentPtr m_pDo...

Can I call a base class's virtual function if I'm overriding it?

Say I have class Foo and Bar set up like this: class Foo { public: int x; virtual void printStuff() { std::cout << x << std::endl; } }; class Bar : public Foo { public: int y; void printStuff() { // I would like to call Foo.printStuff() here... std::cout << y << std::endl; } }; ...

How can you use utility functions with UnitTest++

I'm using UnitTest++ for unit testing C++ code. In my tests, there's a group of tests I repeat several times. What I'd like is for a utility function to perform these tests. In short, I'd like to take this: TEST( foo ) { Foo one; Foo two; // init one & two // lots of CHECK_CLOSE(one.bar, two.bar, 1e-5); in repeating cy...

boost lambda collection size evaluation

I have a function of the form: void DoSomething(const boost::function<bool ()>& condition, other stuff); This function does some work and returns only when the condition is true. The condition has been expressed as a functor argument because I want to supply different conditions at different call sites. Now, this is fairly straightf...

Networking with C/C++ in a Windows enviroment

What is the best way to use sockets on the Windows platform? Basic sockets I guess, TCP/IP. Maybe for a chat client, or just for learning. Could someone give me an example of WININET usage? maybe ftpgetfile() ...

howto Communicate with MYSQL Embedded Server from MySQL++ DLL?

I have write my code using MySQL++ to communicate with the MySQL Embedded Server. at first, I used dynamic link method (use mysqlpp.dll), but it always fail with 1 when do mysql_real_connect(). later i realized that i should not use dll, so i go to use static link method (use mysqlpp.lib) and things goes ok. I think maybe mysql++ can ad...

what is "stack alignment"?

What is stack alignment? Why is it used? Can it be controlled by compiler settings? The details of this question are taken from a problem faced when trying to use ffmpeg libraries with msvc, however what I'm really interested in is an explanation of what is "stack alignment". The Details: When runnig my msvc complied program which ...

Macro expansion in C++

How can I define a macro (or a workaround for this) where the parameter is at the beginning of the line? #define SINGLETON_IMPLEMENTATION(className) \ ##className* ##className::instance_ = NULL; This give a compiler warning (GCC 3.2.3): " '##' cannot appear at either end of a macro expansion" ...

What is the use of passing const references to primitive types?

In a project I maintain, I see a lot of code like this for simple get/set methods const int & MyClass::getFoo() { return m_foo; } void MyClass::setFoo(const int & foo) { m_foo = foo; } What is the point in doing that instead of the following? int MyClass::getFoo() { return m_foo; } // Removed 'const' and '&' void MyClass::setFoo(...

How to convert c++ std::list element to multimap iterator

Hello all, I have std::list<multimap<std::string,std::string>::iterator> > Now i have new element: multimap<std::string,std::string>::value_type aNewMmapValue("foo1","test") I want to avoid the need to set temp multimap and do insert to the new element just to get its iterator back so i could to push it back to the: std::list<m...

C++ development on linux Code::Blocks, EMACS or GVIM

I am not looking for an IDE suggestion for C++ development. I have found many discussions on that and tried EMACS, GVIM and Code::Blocks. I liked Code::Blocks very much than the other two. But it looks like most of the developer community is using tools like EMACS or GVIM. Is there a reason for this? Why Code::Blocks is less used? I fou...

ListView with LVS_OWNERDATA flag

Hello I want to make a CListView that will read his rows from e remote server using socket. The rows may be more than a million that's why i need to read rows only when I need them and may be read them in a groups (with more that 1 row per request). I also need to support sorting by rows. May be I have to use List Control with LVS_OWNE...

Can templates be used to access struct variables by name?

Let's suppose I have a struct like this: struct my_struct { int a; int b; } I have a function which should set a new value for either "a" or "b". This function also requires to specify which variable to set. A typical example would be like this: void f(int which, my_struct* s, int new_value) { if(which == 0) s->a = new_va...

import all variables of parent class

You may have notice that later versions of gcc is more strict with standards (see this question) All inherited members of a template class should be called using the full name, ie. ParentClass<T>::member instead of just member But still I have a lot of old code that does not respect this. Adding using ParentClass<T>::member for ea...

C++: How to open IShellFolder drive folder from a shortcut

I am using the following command in a shortcut to open my virtual drive in Windows Explorer. %SystemRoot%\Explorer.exe /e,::{MyExtension CLSID} The virtual drive uses IShellFolder interface and is a ShellExtension. It has a couple of predefined folders in it. The problem is that I can open the virtual drive in Windows explorer directly ...