You already have it!!

If you are using linux and you have development environment setup then you will find it in the :
/usr/include/c++

In windows I dont know exact location, but you should still able to browse it from any IDE.
Just include the header file and click on it, it should take you to the library file.

I have just run it on Mac, didn't get any compilation error, what platform you are using?

[CODE]

include <iostream>
include <complex>
include <functional>
include <numeric>
include <vector>

using namespace std;

double accumSq(double sum_so_far, double x)
{
return sum_so_far + x*x;
}

void doIt(const std::vector< std::vector<double> > &values )
{
// things happening
double e = sqrt(std::accumulate(values[0].begin(), values[0].end(), 0.0, accumSq))/values[0].size();
// things happening
}

int main(int argc, char *args[])
{
// things happening
std::vector< std::vector<double> > values(3, std::vector<double>());
// fill values in values vector
doIt(values);

return 0;
}
[/CODE]

[QUOTE]No. No. No. 1) I cannot assign or copy-initialize an rvalue (since the left-hand-side does not have a identifier, it is an rvalue). 2) You cannot assign a pointer to a reference, and a pointer is not implicitly convertible to an integral type. 3) You cannot bind a non-const reference to an rvalue (which is what NULL is).
[/QUOTE]

If we say rvalue, isn't it going to change in C++0x, if we want we can hold rvalue and use move semantic. we can use like below:
[CODE]
string&& value = aFunReturningRValue();
[/CODE]

Please correct me if I am wrong.

[QUOTE]4) Via template specialization of a member-function template (if one is already available in the class).[/QUOTE]
Can you please give an example for that?

[QUOTE]The implementation that alwaysLearning0 posted is not only simplified but also generally broken. [/QUOTE]
Yea I know, as I was using pointer. But wanted to keep it very simple as so far I understood our original poster's C++ knowledge is not at advanced level and initially he used pointer for his code.
But because it needs lot of other precaution and checking, I made following comment:
[QUOTE]Ofcourse above code is a very simple implementation and you can add lots of policies with it (like creation policy, deleting policy, threading policy)[/QUOTE]

and.. for this:
[QUOTE]In the few exotic situations that mandate a singleton, it mandates a true singleton with several precautions taken, beyond the simple precautions I laid out in the code above.[/QUOTE]

Because of that I said:
[QUOTE]I would suggest to use the boost/loki singleton class.[/QUOTE]

[QUOTE]Then I would ask why you think you need a Singleton. In my experience, they're only necessary in some pretty exotic situations. In most other cases, the Singleton pattern is more of a band-aid over design flaws than good design.[/QUOTE]

There are several examples I could give where you may need singleton solution, on top my head:
1) Lets say you have a server with multiple(could be 1000) Threads handling events, it needs to maintain a transaction sessions among threads to share, you need a single TransactionHandler singleton which will maintain the transaction store.
2) Logger
....
Actually this list could go on and on, IMHO a server can have several components which could ...

Best way to make a singleton class will be to implement a singleton template which can hold anyclass and can make any class singleton.

Here is a very simplified version of it:

[CODE]

include <iostream>

using namespace std;

//A is a simple normal class
class A{
int x;
public:
A(): x(2){
}
int getX(){
return x;
}
};

//This is the Singlton class which hold any class and make any class Singlton
template <typename T>
class Singletone{
Singletone(){
}

public:
static T* _instance;

static T &Instance(){
    if(!_instance){
        _instance = new T();
        cout<<"1st _instanceance creted..\n"<<endl;
        return *_instance;
    }
    else {
        cout<<"Already Instance exists....so Try Agian\n"<<endl;                }

    return *_instance;
}

};

template <typename T> T *Singletone<T>::_instance = 0;

//Creating a singleton of A
typedef Singletone<A> ASingleton;

int main()
{
//we will use ASingleton::Instance() to access the single instance of class A.
cout << ASingleton::Instance().getX() << endl;

return 0;

}

[/CODE]

Ofcourse above code is a very simple implementation and you can add lots of policies with it (like creation policy, deleting policy, threading policy)

I think you are doing it for learning purpose, hence i am providing you a very simple code.
But If you want to use it for production purpose, then I would suggest to use the boost/loki singleton class.

[QUOTE]You sure can but they must be initialized thus declared static[/QUOTE]
A class can also have non static constant, it has to be initialized at initialization list.

[CODE]
class A{
const int a;
public:
A(int a) : a(a){
}
};
[/CODE]

You can not do [CODE]int &var=NULL;[/CODE] and there is a reason behind it.
any & is reference and once it is initialized, it can not be initialized again, so NULL is not a varaible/memory which & refer to.
You can not even do this: [CODE]int &var=2;[/CODE]
but you can do [CODE]int *p = NULL;[/CODE], you can do this because you can reset/intialized a pointer whenever you want.

While writing I realized it could be so big!!!!!!! but

Ok, so here it goes:

Model: A collection of classes which actually represent your data, in more plain words: A simple POJO class which actually will represent a table in database. Lets say database has a STUDENT table, with column Name and ID, then your Student class should also have member variable name and id.
A model should be persistent with the table.

Now the way you can make a model persistent is a huge thing and can be implemented in so many different ways and most of the time this is actually one of the deciding factor of a framework being light or heavy.

Controller:
A set of classes which actually controls the behavioral of the application: again in plain words, when you submit a request, a controller class should pick it up and call the business logic. business logic can be a part of the controller layer or can be separate layer as well. When a controller receives a request, it knows the business logic class which will handle this (a controller can be a business component itself, it depends how you design your framework ) and after processing the request it knows which data to show (keep reading view to understand this)

View: View is the pure PHP/JSP/ASP pages which actually will show the data, in plain words: whatever we see on browser is the view. So view has to show data and we represent data by ...

Are you asking about a PHP related question? Like how you can make use of PHP to interact between several layers?

Or are you asking about a more general MVC related question like how each layer should interact?

Sorry I didn't get your question.

BTW there should be many light weight MVC framework anyway. I would suggest to download free one and start reading the code. Best way to learn lot of things in relatively short period of time.

[URL="

[QUOTE]Thank u for ur advice but it would be better if u elaborate little better as i went through Dijkstra' Algo and got that it is for weighted graph for least weight path rather than least number of path .[/QUOTE]
Dijkstra is a least number path problem, it will give you shortest path for a single source,
But after reading your prblem, so far I understand you need all pair shortest path, which will give you the shortest paths from every source to every destination in O(n^3)

After finding the shortest path, you need to find the average of those path per source, which is another O(n^2) search, then just need to give output of the lowest average one.

Complexity = O(n^3) + O(n^2)
you can ommit O(n^2)
so basically its O(n^3)

Here is the all pair shortest path algo:
[URL="

Hi,

Can you please check sizeof(real) and sizeof(double) is same or not, may be lame check but only invalid memory access is the reason that making your first matrix corrupted.

On a first glance, code looks so far fine, only potential invalid memory access in the above code is while giving output, so lets check the size of those two.

Second is, can you use valgrind to see where the invalid memory access is happening, valgrind should point you exactly where you are accessing the invalid memory.

it comes free with most linux distro.

Another thing I want to point out is: Why you are allocating memory in the intializatin list, its very dangerous and could produce potential memory leak which is very hard to debug, consider the following code:

[CODE]
class A{
AnotherObject a, b;
public:
A(): a(new AnotherObject()), b(new AnotherObject()){ //What will happen if initialization of a is successful but b fails, potential memory leak.
}
}
[/CODE]

Solution of this is smart pointers. if you store value in smart pointer, lets say you you store a in the smart pointer, even b fails, smart pointer will take care of memory deallocation of a.

Last but not least, I would suggest not to define any Exception specification except throw(), it doesn't do any good.

Hi,

Only way I could help now by giving some suggestions. Seeing your code I have feeling that you need to read some basic C++: reference, pointer, memory allocation.

First read a programming book/site to make sure you understand the basic memory handling using c++,
Here is a good site to start with:
[URL="

Hi,

A straight forward error is:

[CODE]
void lsmain(lua_State* L, SDL_Event event){ //Takes a SDL_Event
}
//and from main you are passing:
lsmain(L, &Event); //address of SDL_Event, this would definitely cause crash and i am kind a surprise why its not giving an compiling error!

[/CODE]

Now about the thread memory allocation, you dont need to allocate any memory for the thread as all the thread libraries take care of memory allocation.

If you want to develop any C/C++ project, first thing you need to read about memory allocation.
It will help you to avoid countless hours of debug!!!

you input and output operator takes a CGuser by reference.
Do following:

[CODE]
cout<< *user;
[/CODE]

Why I always think in hard way??!!

Anyway look at the m4ster_r0sh vector example and see how he is taking input of the number of nodes and using vector to save nodes.

After saving you can access the nodes and do whatever you like.

Why you want to declare N objects with name n1, n2, n3..nN?
It wont help you any how.

There is ways to generate name at compile time but not on runtime but still those are mainly for template programming to generate struct/class type on fly.

Can you explain why you want to do this?

anyway, if you want to give a node identifier anyway, why not change your Node class and save the node identifier

[CODE]
class Node{
int identifier;
public:
Node(int id): identifier(id){ }
}
[/CODE]

seeing at your code looks like you already have some id to identify the object.
STL containers are mainly there to hold the unnamed objects, you wouldnt get any benefit by giving names like n1, n2..nN to all the nodes. you can identify a node using the identifier anyway.

If you explain little bit more whats your goal is, then I might give you a better example.

Hi,

Couple of things gone wrong in your program, I am just fixing the Person class and pointing out some issues, see the inline comments:

[CODE]
//Now it should compile, fix your other class like this
class Person
{
protected:
string name;

public:
Person():name(""){cout << "Default Person Constructor" << endl;} // You can not do Person():name('\0'), '\0' is a charecter and string type //variable can not be initialized by a character
Person(string theName):name(theName){cout << "Parameterized Person Constructor" << endl;}
Person(const Person& theObject);
string getName() const{return name;}
Person& operator=(const Person& rtSide)
{
name = rtSide.name;
return *this;
}
friend istream& operator >>(istream& inStream, Person& personObject)
{
inStream >> personObject.name;
return inStream;
}
friend ostream& operator <<(ostream& outStream, const Person& personObject) //You are returning outStream and it is a ostream type object so why is the return type you set istream
{
outStream << "Person's name: " << personObject.name << endl;
return outStream;
}
};

[/CODE]

Following link will show you all the string class constructors you can use:
[URL="

fork() creates a copy of a parent process and all the descriptor is opened by the parent process is also shared by forked children.

If you use fork() to create children, then parent process or a child process doesn't need to wait for other children or parent to get finished.

In plain words all fork() children should be able to run simultaneously.

As sergent said, can we see the code you are using to fork()?

You are freeing memory twice:

[CODE]
Street::~Street()
{
destroyHouses(); //your memory is getting free here with destructor
}

// and you are manually deleting again in the main for Street1
Street1.destroyHouses();
[/CODE]

So, when destructor of Street1 is trying to free the memory again, its crashing as that memory is already freed by you by calling Street1.destroyHouses();

What problem you are facing?

several things have gone wrong here.
But my first suggestion is use stl::vector

See inline commands below:

[CODE]

include <iostream>
include <string>

using namespace std;

string test()
{
string a[5] = {"Hello","World","How","Are","You"};

return a; //You are trying to return a local variable, once local variable out of scope, programs frees the memory, so you are returning an invalid memory.

}

int main()
{
string b[5];

b=test(); //You can not assign an array like this.

for(int i=0;i<5;i++)
    cout << b[i] << endl;

return 0;

}
[/CODE]

Now solution of your problem is, First read about local variable and pointer/reference of local variable.

second, there is a relation between an array and a pointer, you can refer an one dimensional array by pointer.
two dimensional array can be refered as double pointer and so on..

[CODE]

include <iostream>
include <string>

using namespace std;

string *test() //Notice the pointer..
{
string a[5] = {"Hello","World","How","Are","You"};

return a;  //still you are returning an invalid memory as end of this method, this memory will be invalid.

}

int main()
{

string *b=test(); //Notice the pointer to catch the array,

for(int i=0;i<5;i++)
    cout << b[i] << endl; //This will get crash as b is pointing to an invalid memory

return 0;

}
[/CODE]

you need to read about scope of variable.

I hope it helps.

What is the core file size?
May be core file is getting discarded.
Try to set "ulimit -c unlimited" which will allow you to generate full core dump.
then use command: file coredumpfile, which will show you which program actually generated the core, just to make sure you are debugging the right core.

Then use the following command:
gdb -c coredumpfile ./YourProgram

then give command: "info threads" it will show you all the threads, usually the last thread is the one which crashed.
You can then debug individual thread by selecting the thread number you got in the last command
"thread 1" which will take you to that thread
or you can give command: "thread apply all bt" to see the back trace of all the threads.
or "thread apply threadno bt" to see the back trace of the last thread.

in the bt, you can see exactly where it crashed.

In the multithread programs, usually program crash because of invalid memory access, use share_pointer and locking as much as possible to control memory access.
There are some performance bottleneck for using those, but at least your program will not crash.

there is other tool too, valgrind is a very good tool to check the memory leaks and invalid read.

[url]http://valgrind.org/docs/manual/mc-manual.html[/url]

you can paste here your core dump, I can have a look if you like.

Yea, you are right, you wont get the address of the function compile time.

[QUOTE] I just want to provide an easier way to call the Bind-method in form of avoiding the use of <>.[/QUOTE]

Doesn't argument deduction shown on my last post help?

Have you been able to debug the crash? What error you are getting? Do you see the core file?

If a thread is crashed then the program is also crashed, compile your program with -g option so that when it crashes it will generate the core file.

And then you can debug core file to find out exactly where it crashed.

Use gdb to debug. Following link has some helpful commands to debug the threads.
[URL="

What do you mean by setting name of the thread? Why you need a name?
In Posix you can refer to a thread by it's thread id.

pthread_create creates a thread and returns the handler of the thread which you can save and use.

[CODE]

include <pthread.h>
include <stdio.h>
define NUM_THREADS 5

void PrintHello(void threadid)
{
long tid;
tid = (long)threadid;
printf("Hello World! It's me, thread #%ld!\n", tid);
pthread_exit(NULL);
}

int main (int argc, char argv[])
{
pthread_t threads[NUM_THREADS];
int rc;
long t;
for(t=0; t<NUM_THREADS; t++){
printf("In main: creating thread %ld\n", t);
rc = pthread_create(&threads[t], NULL, PrintHello, (void
)t);
if (rc){
printf("ERROR; return code from pthread_create() is %d\n", rc);
exit(-1);
}
}
pthread_exit(NULL);
}
[/CODE]

and also gettid returns you the current thread id.

Can you explain little bit more why you need to set a thread name, then i will be able to give you more proper solution

BTW its a C code solution which I just copied from cloud, you should write a proper cpp code to full fill the RAII idiom

Hi,

Why you want to bind member function type with a static bind method? you wont be able to call it without having proper address of class member function.

Anyway, I hope following code helps, let me know if it works?

[CODE]

include <iostream>

using namespace std;

template <typename T>
class SomeFunction{
T instance;
public:
template <typename FunPtr>
void Bind(T _instance, FunPtr funPtr){
//Bind your funPtr here.
//use a place holder to hold the FunPtr type as you will want to use it
}
};

template <typename T, typename FunPtr> //Let argument deduction find out the type.
void Function(T instance, FunPtr funPtr){
(instance.*funPtr)();
}

class AClass{
public:
void ClassFun(){
cout << "Class is having fun" << endl;
}
};

int main() {

    AClass x;
    Function(x,&AClass::ClassFun);

    return 0;

}

[/CODE]

Can yo explain what exactly your bind method will do and what you want to do after binding the type? then may be i could give more proper example.

Can you give more information to understand what exactly the project requirements are.

Initially I thought you want to know about the tools to find out the performance of a program/server, Rubberman already gave a reply for this. I want to add my 2 cets. Valgrind, one of the top open source to find out the performance,memory leak of a program. valgrind now a days come with lots of linux distribution.
efence, electric fence also a library to debug malloc.
[URL="

[URL="

You wouldn't convert the 2d array into the heap, you will still traverse the graph on basis of the 2d array, in heap you will only put the height, and location of the height.

Consider this data structure:

[CODE]
class Node{
int height,
int row;
int col;
}
[/CODE]

you will put this node in to the heap, and heap will construct on basis of the value of the height.
You will still need the 2d array to find out the adjacent nodes.

Looks like this problem can be solved using Breath first search (BFS) with Priority queue.

you can use min heap to solve this problem.

[URL="