#include <iostream>
#include <cstdlib>

using namespace std;

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

 return 0;  

it says cannot convert Z to Y in assignment.

9 Years
Discussion Span
Last Post by NathanOliver

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.


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.

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.