c++

c'tor and d'tor calls

How can I check if my constructor or destructor were ever called? Thanks in advance for any idea, I'm learning C++. Because of implicit calls I don't know if they were actually called. ...

C++ maximum non negative int

Is the following going to work as expected on all platforms, sizes of int, etc? Or is there a more accepted way of doing it? (I made the following up.) #define MAX_NON_NEGATIVE_INT ((int)(((unsigned int)-1) / 2)) I won't insult your intelligence by explaining what it's doing! Edit: I should have mentioned that I cannot use any standa...

difference between operator overloading and operator overriding in c++?

hi.. what is main difference between operator overloading and operator overriding in c++? please explain with example? Edit1 :- Any good web links that would help a novice programmer to improve and be confident about the language he/she is learning. ...

How does virtual method invocation work in C++?

How does Virtual Method Invocation work in C++? ...

How to nicely output a list of separated strings ?

Usually, when I had to display a list of separated strings, I was doing something like: using namespace std; vector<string> mylist; // Lets consider it has 3 elements : apple, banana and orange. for (vector<string>::iterator item = mylist.begin(); item != mylist.end(); ++item) { if (item == mylist.begin()) { cout << *item; } ...

What is the difference between c++, objective-c and objective-c++?

Hi Guys, I want to know the difference between c++ and objective-c and objective-c++. Can any one give me the difference and Can we use the c++ for iPhone development Thank you, Madan Mohan ...

Using Boost.build to include a library

I am using boost.build to compile a c++ code which references a library, CGNS, but am having some difficulty with using boost.build to do so. CGNS compiles to a library, with a folder for the platform, for example [path]/LINUX for the linux build. I would like to include the library [path]/LINUX/libcgns.a in the build. I would like th...

C++ Prime factor program 2 problems.

Okay so I"m writing a program (in C++) that is supposed to take a number, go through it, find out if it's factors are prime, if so add that to a sum, and then output the sum of all of the imputed number's prime factors. My program successfully seems to do this however it has 2 problems, 1) The number I am supposed to test to see the ...

how to link header files in c++

Hi iam new to write programs in c++ by using header files and including them. //a.h #ifndef a_H #define a_H namespace hello { class A { int a; public: void setA(int x); int getA(); }; } #endif //a.cpp #include "a.h" namespace hello { A::setA(int x) { a=x; } int A::getA() { return a; } } ...

Would using a library like Boost be acceptable at work? (C++)

Possible Duplicate: Is there a reason to not use Boost? In my distaste for over-re-using small libraries that I had designed for different purposes (filesystem, network etc) for each project I had become to like the taste of using a larger general purpose library such as Boost. If it saves time (and money depending on the ge...

custom allocator using move for vector of thread

I'm currently learning about concurrency in C++ and came across using a vector of threads, which I believe will be possible in C++0x. However, my current compiler doesn't appear to have an implementation of move-aware containers and so I get errors generated because std::thread::thread(const std::thread&) is deleted, ie I can only use th...

why my heap is corrupted?

i'm getting an error - heap corruption, can't figure out why. my base : h: class Base { public : Base(char* baseName, char* cityName); virtual ~Base(); list<Vehicle*>::const_iterator GetEndList(); void PrintAllVehicles(ofstream &ResultFile) const; char* GetBaseName() const; char* GetLocation() const; v...

Very basic C++ error

Hey guys, I'm writing the simplest thing ever, just creating an ifstream to read in a text file and I have a weird error. Here is the code (note : the '<' missing for iostream and fstream are well written in my code but I couldn't write them here) #include "genlib.h" #include "simpio.h" #include "random.h" #include "vector.h" #include "...

Why would you "default" a copy/move constructor or a destructor?

C++0x lets you specify certain functions as defaulted: struct A { A() = default; // default ctor A(A const&) = default; // copy ctor A(A&&) = default; // move ctor A(Other); // other ctor ~A() = default; // dtor A& operator=(A const&) = default; // copy assignment A& operator=(A&&) =...

question about struct and pointers

let us consider following code #include <stdio.h> #include <iostream> using namespace std; typedef struct bf_{ unsigned x:4; unsigned y:4; unsigned z:4; unsigned w:4; }bf; int main(){ unsigned short i=8; unsigned short j=9; bf* bitfields=(bf *)&i; bf*bit=(bf*)&j; bitfields->w=12; printf("%d\n...

Initialize already declared char array in C++

Hello, I want to use something like this: char theArray[]=new char[8]; theArray= { 1,2,3,4,5,6,7,8}; instead of char theArray[] = { 1,2,3,4,5,6,7,8}; Is a similar thing possible? ...

C++ reading in specific segments of data from a file redirected to my program

I'm working on a program that takes a redirected file as input. For example, if my program was called foo I would call the program with ./foo < input.txt. The files I'm running through my program are supposed to be formatted with a single integer on the first line, two integers on the second line. So something like 3 1 8 I'm finding t...

Returning an argument pointer to an object

In C++ for Windows, I have some object factory that is supposed to create a series of Info object by passing a pointer to the object to a Create function and returning a created object. void CreateInfoObject(AbstractInfo** info); // The creation function AbstractInfo is a base class of which we have many types of Info objects derive...

implement bonjour sdk in visual c++ windows forms application

Hello I have succesfully implemented the bonjour sdk in a visual c++ console app. but when I am trying to implement the same code in a windows forms app (visual c++) I am receiving weird errors probably related to some local heap problem with the bonjour dll. The following assertion in the file dbgheap.c fails: /* * If this ASSERT f...

C++ map declaration under g++

I have such declaraition using namespace std; map < string, string> attr; if i write it in class or in global namespace it is compiled ok, but if I write it inside function it doesn't. Why? How can I solve it ? ...