#include <iostream>
#include <cstdlib>

using namespace std;

struct A {
      A *B;
       };
       
       struct C{
              C*D;
              };
int main()
{
 
 
 A * Z = new A;
 C * Y = new C;
 
 Z = Y;

 
 cin.get();
 return 0;  
}

it says cannot convert Z to Y in assignment.

Recommended Answers

All 7 Replies

that is because you do not have a function that can convert struct A to struct C. you must supply one to the compiler otherwise it doesn't know what to do

So I have to overload the assignment operator?
I was never really good with that.

yep you can do that or you can write a conversion function that takes in a C and will return an A. so if an A is 3.26 times a C you could have

A * convertC(C*);

A * convertC(C * c)
{
            A * a = new A;
            a.B = c.C * 3.26;
            return a;
}

this example assumes that the members are some form float but from what i can tell your member variables have no type.

I don't see how that function allows me to have

a pointer from another struct point to pointer from another struct

oops sorry typo &a.A = &c.C * 3.26; i forgot to dereference the pointers before i use the values. also what is the data type for the member variables in the struct.

It's a pointer.
And i'm not sure where the 3.26 came from

a pointer to what? another A? the 3.26 was just an example that if both members were float and there was a conversion difference of 3.26 that you could multiply and get an equivalent answer. think of converting Celsius and Fahrenheit and they were structs in your program.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.