c++

how to return an null tr1::shared_ptr and test if it is null

Hi, I have a function getA() with following signature : class A { public: typedef std::tr1::shared_ptr <A> Ptr; //other member functions.... }; class B { pubic: A::Ptr getA(); }; And, I want to return an empty pointer in getA() in same case; Also, as a user of Class B , I need to test if the return value of getA() is null bef...

Accessing public inherited Template data members

Hi, I require some clarification on the question why do we need the scope resolution operator or this pointer to access publicly inherited members from a template base class. As I understand it is for adding clarity but then how does this add any further clarity than just point that it is a member of the class. To make my question clear...

How to prevent member variable of Object X from going out of scope when shared_ptr of X is returned from the stack frame of a function call in C++?

#include <iostream> #include <fstream> #include <map> #include <vector> #include <string> #include <tr1/memory> #include <algorithm> #include <utility> class X { public: int x; X(){ std::cout << "Inside X cons" << std::endl; } X(X& _x){ std::cout << "Inside Copy cons" << std::endl; this->x = _x.x; ...

i want to show the output of my programe written in c++ to a xml file.

int countNodes( TreeNode *root ) { // Count the nodes in the binary tree to which // root points, and return the answer. if ( root == NULL ) return 0; // The tree is empty. It contains no nodes. else { int count = 1; // Start by counting the root. count += countNo...

Accessing an object from a different class - Design

I have three classes, TImageProcessingEngine, TImage and TProcessing TImageProcessingEngine is the one which i am using to expose all my methods to the world. TImage is the one i plan to use generic image read and image write functions. TProcessing contains methods that will perform imaging operations. class TImageProcessingEngine {...

How Callback functions are usefull while building and DLL

Are callback functions equivelent to events in C#(.NET). What I understand about callback function is, it is a function that is called by a reference to that Function. Example Code will be: void cbfunc() { printf("called"); } int main () { void (*callback)(void); callback=(void *)cbfunc; callback(); re...

creating datatypes at runtime

Hi, I have a scenario where I am given data records at runtime. The datatype of the cells of the record are variable and only known at runtime. How wil I store these records? For e.g., At runtime, I get record_Info = "char[]","int16","int32" Then I get records = "abc" "2" "30", "def" "3" "40" how can I store these when I cant initial...

How to get distinct values from an arrays of different sizes?

Q: arr1[]={1,1,1,2,5,5,6,6,6,6,8,7,9} Ans: values[]={1,2,5,6,7,9} Q: arr1[]={1,1,1,2,5,5,6,6,6,6,8,7,9,101,1502,1502,1,9} Ans: values[]={1,2,5,6,7,9,101,1502} here is what i tried but not working for(int i=0;i<(index-1);i++) { if(data[i].age != data[i+1].age) { c=new list; c->value=data[i]...

Why no sanity checks in legacy strcpy()

Following is the most popular implementation of strcpy in traditional systems. Why dest and src are not checked for NULL in the start? I heard once that in old days the memory was limited so short code was always preferred. Will you implement strcpy and other similar functions with NULL pointer checks at the start now days? Why not? cha...

Extern Symbols in Object files

Hi, I am facing a strange issue, but unable to simulate it a smaller scale. The problem is my symbol table has an entry of my extern symbols. These are declared in a header file. Defined in some other file - header.c Header file header.h extern void rlog(int , char*, ...); extern int SetGDebug(string); extern int GDebug; test.cpp C...

PUSH an array C++?

How would I dynamically add a value (push) to an array? I could do this in AS3, but I can't find a function for it in C++. ...

Why mkdir fails to work with tilde (~)?

When I write mkdir("~/folder1" , 0777); in linux, it failed to create a directory. If I replace the ~ with the expanded home directory, it works fine. What is the problem with using ~ ? Thanks ...

C2065 identifier undeclared

Hi, In my Service.h I have: #include "Configuration.h" and in my class: private: ConfigurationInterface* configuration_; Then, in my Service.cpp: Service::Service(Foundation::Framework* framework) : framework_(framework) { configuration_ = new Configuration(); } and later... const Info GetInfo() { retur...

Question about references

I think the following is really basic but I don't really get what would be the "advantages" of one of these code. Having this: int main() { int a = 10; f(a); return 0; } What would be the difference between void f(int& a) { int& b = a; } and void f(int& a) { int b = a; } In particular, in the case where f wo...

passing an unmanaged function pointer callback to managed code using C++ interop

Hi all, I'm trying to add some managed code into an existing c++ GUI application. I'd like to get a functional callback working...specifically, I'd like to pass a method pointer from UNMANAGED code to MANAGED code and have the managed code invoke the callback. I'm looking at something like this: typedef int (__stdcall *ANSWERCB)(int)...

What's the point of boost::multi_index_container::index<Tag>::type ?

If you have a boost::multi_index_container< > with multiple indices, there are obviously multiple ways to iterate over it - each index defines a way. For instance, if you have an index with tag T, you can iterate from container.get<T>().begin() to container.get<T>().end(). If you try to do so in a for-loop (and do not have C++0x auto),...

Is it safe to manipulated streambuf after doing boost::asio::async_read?

I know it's not safe to manipulated streambuf while async_write working as stated by asio author on boost mailing list. What I want to know is, is it safe to manipulated streambuf after async_read? Example: async_read(socket_, recv_streambuf_, ...); // manipulated while async_read is working // for example, after I call async_read, rec...

C++ from a Java-view: I must have missed a few things

Before anything, let me first clarify that the below thoughts are purely my personal opinions and due to my limited knowledge. I have no intention whatsoever to say that C++ is not cool. I've been programming C++ for like a year and I think it really has some cool features. Nevertheless, I feel a bit empty and disappointed as I didn't ...

Encapsulating boost::random for ease of usage to replace rand()

Hello, for my program I need pseudo random integers with different ranges. Until now I used the rand() function but it has it's limitations. I found the boost::random library to be a much better replacement but I didn't want to create random generators all over the place. ( I need random integers in many classes, because it's a stress t...

How are constructors and destructors implemented in C++?

I have 2 classes Base and Derived (derived publically from Base). When I write - Derived * d1 = new Derived; delete d1; Compiler sees that d1 is a Derived type object. So it calls the derived class constructor (which calls the base class constructor). I have 2 questions here - 1) Why do we follow this order? 2) How do these constru...