hi

i'm having a problem when i use pointer to pointer
i've tried my best to make this work .. but it didn't
i've got a run time error!

PLEASE .. Please .. please i need help :'(
if any one have tutorial about how can i work with pointer to pointer please put it 4 me

Can any one help me with this code

#include<iostream>
using namespace std;

class Example
{
	Example **object2;
	int size;
public:

   Example()
   {
      size=2;
      Example **object2=new Example* [size];
      for(int i=0; i<size; i++)
           object2[i]=NULL;
   }

    void print2()
   { 
      int i=0;
      while (i<2)
       {
          (*object2)->print(); // <<<< run time error
            i++;
            object2++;
        }
        cout<<"Dosn't Work !"<<endl;
      }

void print(){ cout<<"\nPlease Help ! "<<endl;}

};


int main(){

 Example **object=new Example* [2];
for(int i=0; i<2; i++)
 object[i]=NULL;

 (*object)->print();
 (*object)->print2();

	return 0;
}

It doesn't work because line line 23 object2 is a null pointer. The declaration on line 13 is hiding the declaration line line 6, so line 13 is not allocating memory for line 6. Also, line 15 is making the array of NULL pointers.

thanx alot 4 ur help .. i've try to edited but i still have the run time error

#include<iostream>
using namespace std;

class Example
{
	Example **object2;
	int size;
public:

   Example()
   {
      size=2;
      object2=new Example* [size];
   }

    void print2(Example &temp)
   { 
	  *object2=&temp;
      int i=0;
      while (i<2)
       {
          (*object2)->print(); // <<<< run time error
            i++;
            object2++;
       }
        cout<<"Dosn't Work !"<<endl;
      }

void print(){ cout<<"\nPlease Help ! "<<endl;}

};


int main(){

 Example *temp=new Example;
 Example **object=new Example* [2];
for(int i=0; i<2; i++)
 object[i]=NULL;

 (*object)->print();
 (*object)->print2(*temp);

	return 0;
}

i'm happy finally i know how to use code lol!

still the same problem as before, but all you did was move it around a bit. What exactly are you trying to do ? I know you want to use double pointers but what is the object of the code you are posting ?

If you are attempting to create a 2d array then do it like this:

Example **object = new Example*[2];
for(int i = 0; i < 2; i++)
   object[i] = new Example;
#include<iostream>
using namespace std;

class Example
{
	Example **object2;
	int size;
public:

   Example()
   {
      size=2;
      object2=new Example* [size];
   }

    void print2(Example &temp)
   { 
	  *object2=&temp;
      int i=0;
      while (i<2)
       {
          (*object2)->print();
            i++;
            object2++;
       }
        cout<<"Dosn't Work !"<<endl;
      }

void print(){ cout<<"\nPlease Help ! "<<endl;}

};


int main(){

Example *temp=new Example;
Example *object=new Example[2];
 
object->print();
object->print2(*temp);
return 0;
}

Try this, its working

thanx alot guyz .. i'm trying to use pointer to pointer with functions without having a run time error ..

Asat232 .. thanx aloOoot 4 ur help :)

This question has already been answered. Start a new discussion instead.