0

I am writing a simple program to add two complex number using struct. All goes well except that when printing the values, I get an error that I am dereferencing an incomplete pointer.

Here is the code:

struct complexNumber * n1 = (struct complexNumber *) createNumber(10,10);
struct complexNumber * n2 = (struct complexNumber *) createNumber(03,12);
struct complexNumber * n3 = (struct complexNumber *) addComplexNunbers(n1,n2);

printf("Real Part: %d Imaginary Part: %d",n3->real,n3->imaginary);  
An SO User
  • 24,612
  • 35
  • 133
  • 221
  • duplicate? http://stackoverflow.com/q/2700646/489590 http://stackoverflow.com/q/9606435/489590 – Brian Cain Sep 18 '13 at 13:15
  • 3
    Have a look down on the right side of this page, and see how many related question referring your question's title already exists. You most propaply have been pointed to those when creating this question. – alk Sep 18 '13 at 13:22

2 Answers2

3

You need to include the header fine, which defines struct complexNumber.

Kiril Kirov
  • 37,467
  • 22
  • 115
  • 187
2

The whole point of using incomplete type is to make the program able to use a pointer to an object, without knowing the implementation of said object.

Therefore, it never makes any sense to access the pointed-to contents of an incomplete type.

Lundin
  • 195,001
  • 40
  • 254
  • 396