0

hi all,

I have a class A that has a char* var, operator and methods.
In addition I have a global func(char*s). I would like to run this code from the main function by adding operators to my class, I need help writing them.

A* pA; 
... 
A** ppA = pA; 
func(*ppA);

thanks...

4
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by BanKuZ
1

Hi BanKuZ, welcome to DaniWeb!

Which operator would you like to use? Maybe you can also post your class structure, I'm not sure I followed what is going on from what you posted.

David

0

Thank you for the fast replay,
I already have a MYclass* to char* conversion operator on the code and it work fine.
I having problems to convert from MYclass* to MYclass** and from MYclass* to char*.
I need them all to work simultaneously.

0

My class is very simular to this one:

class Mystring {
        public:
	char *s;
	Mystring(const char *);
	Mystring();
       ~Mystring(){}
    
        Mystring operator=(const char* str)
        {

           strcpy (s, str);
           return *this;
        }
            operator char *()//Conversion operator
	{
                return this->name; 
        }
	//...
};

Thank you for your help.

Edited by BanKuZ: n/a

0

A dataType** is a pointer to a pointer to an instance of dataType (2-levels of indirection instead of 1).

int myInt = 150;
int *pMyInt = &myInt;
int **ppMyInt = &pMyInt;

You'll have to write your converter to return a pointer to the pointer you are trying to convert.

Edited by Fbody: n/a

0

I know, tried these two:

Mystring** operator=( Mystring* A) 
          {
		Mystring** ppTemp= &A;
		return ppTemp;
           }
	
	operator Mystring **()//Conversion operator
	{
        return *this; 
        }

It didn't work. Am I doing something wrong?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.