c++

Why Access Violation for cout And Stack Overflow for printf

Hi, I wanted to know Why Access Violation occurs for cout And Stack Overflow for printf in the following two code snippets. I wanted to know why Access Violation for the First code instead of the Stack Overflow. First Code Which i get Access Violation : void Test(); void Test() { static int i = 0; cout << i++ << endl; ...

Best way to merge hex strings in c++? [heavily edited]

I have two hex strings, accompanied by masks, that I would like to merge into a single string value/mask pair. The strings may have bytes that overlap but after applying masks, no overlapping bits should contradict what the value of that bit must be, i.e. value1 = 0x0A mask1 = 0xFE and value2 = 0x0B, mask2 = 0x0F basically says that the...

Extracting C / C++ function prototypes

I want to do this: extract_prototypes file1.c file2.cpp file3.c and have whatever script/program print a nice list of function prototypes for all functions defined in the given C / C++ files. It must handle multi-line declarations nicely. Is there a program that can do this job? The simpler the better. EDIT: after trying to compile ...

Winsock2: How to allow ONLY one client connection at a time by using listen's backlog in VC++

Hi Everyone, I want to allow only one connection at a time from my TCP server. Can you please tell, how to use listen without backlog length of zero. I m using the code(given below), but when i launch 2 client one by one, both gets connected. I m using VC++ with winsock2. listen(m_socket,-1); passing zero as backlog is also not work...

Are large include files like iostream efficient? (C++)

Iostream, when all of the files it includes, the files that those include, and so on and so forth, adds up to about 3000 lines. Consider the hello world program, which needs no more functionality than to print something to the screen: #include <iostream> //+3000 lines right there. int main() { std::cout << "Hello, World!"; retu...

C++ Abstract class construction and destruction

class base { base () { } virtual ~base () { } } class middleBase { middleBase () { } middleBase (int param) { } ~middleBase () { } } class concrete : public middleBase { concrete () { } concrete (int param) { // process } ~concrete () { // delete something } } Error is : undefinded reference to "middle...

C++: iterating over a list of a generic type

Yet again I find myself struggling with the C++ syntax. I'm trying to iterate over a list of generic objects. That is I have objects of a class Event<Q>, crammed into a std::list<Event<Q> >. So I'm trying to get an iterator over the list and intuitively thought that std::list<Event<Q> >::iterator it; for (it = events.begin(); it != ev...

what is the assert function

hi i ve been studying on openCV tutorials and came across with the "assert" function what does it do thanks ...

Creating a dll which links to another dll (MSVS2008 C++)

Hello all, I am currently creating my own framework in C++ (MSVS 2008) which exports a dll with a bunch of functions for a user of my framework to use/call. In the beginning, when my project was still small, all worked fine. I compiled my project. A MyFramework.dll and MyFramework.lib were spit out. I pretended to be a user; put the MyF...

openCV: image on image

hi i want to paste an image to a captured video frame on the coordinates which i determined i asked that before and i have been told to use cvCopy and cvSetImageROI but i dont want to crop on those coordinates i want to add another image maybe its the right way but i didnt understand it (if its right pls explain it) thank for sugges...

Is it possible to change the temporary object and to pass it as an argument?

Is it possible to change the temporary object and to pass it as an argument? struct Foo { Foo& ref() { return *this; } Foo& operator--() { /*do something*/; return *this; } // another members }; Foo getfoo() { return Foo(); } // return Foo() for example or something else void func_val(Foo x) {} void func_ref(const Foo & x) ...

memcpy() crashes randomly

I am using memcpy in my application. memcpy crashes randomely and below is the logs i got in Dr.Watson files. 100181b5 8bd1 mov edx,ecx 100181b7 c1e902 shr ecx,0x2 100181ba 8d7c030c lea edi,[ebx+eax+0xc] 100181be f3a5 rep movsd 100181c0 8bc...

C++ fixed length string class?

Is there anything like this in Standard C++ / STL? Ideally it should be constructed like fstring s = fstring(10); I need to sometimes construct or have a string of fixed size. Sometimes to be able to read / write only that many characters into a stream. Edit: Note that the size is only known at runtime, and is different from one to...

What's the ampersand for when used after class name like ostream& operator <<(...)?

I know about all about pointers and the ampersand means "address of" but what's it mean in this situation? Also, when overloading operators, why is it common declare the parameters with const? ...

"Access violation reading location" while accessing a global vector..

Hello there, -- First of all, I don't know whether the vector can be called as a "global vector" if I declared it under a namespace, but not in a class or function. -- I'm now writing a simple Irrlicht (http://irrlicht.sourceforge.net) wrapper for my game to make things simpler and easier, but recently I got an "Access violation readin...

Returning a const reference to vector of an object

Hi there, I have 2 questions related to the same problem: 1) How to return a reference to a vector which belongs to a class. I have this class: class sys{ protected: vector<int> s; public: sys(); vector<int>& getS() {return s;} //(1) }; (1) should return the reference of the vector s. However in the main: main(){ ...

Use CArray class from MFC in C++ Builder application

Hello. There is a need to pass CArray instance to an external DLL from my application written in C++ Builder. Is there a way to utilize MFC from C++ Builder? If yes, how? Addendum: this DLL is not mine and I cannot change it. ...

Fastest way to scan for bit pattern in a stream of bits

I need to scan for a 16 bit word in a bit stream. It is not guaranteed to be aligned on byte or word boundaries. What is the fastest way of achieving this? There are various brute force methods; using tables and/or shifts but are there any "bit twiddling shortcuts" that can cut down the number of calculations by giving yes/no/maybe co...

what is the most unobtrusive way of using precompiled headers in Visual C++?

Say I have a single project, with files A.cpp, B.cpp, C.ppp and matching header files (and that's it). The C++ files include system headers or headers from other modules. I want to compile them to a library with command line actions (e.g., using Make), using 'cl', with the precompiled headers feature. What are the steps I should do? Wh...

Creating a new primitive type

Is there a way to create a new type that is like one of the basic types (eg char), and can be implcitly converted between, but will resolve diffrently in templates, such that for example, the following code works? typedef char utf8; template<typename T>void f(T c); template<> void f<char>(char c) { std::cout << "ascii " << c << std:...