2 Replies - 701 Views - Last Post: 17 September 2012 - 03:44 PM Rate Topic: -----

#1 zerubafu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 19-February 12

D Programming - How do you go about importing code modules?

Posted 16 September 2012 - 11:03 AM

Using the D programming language to attempt to design a complex number calculator I created the following code for two modules, one named complex.d and main.d:

complex.d:
module complex;

class Complex
{
	int real;
	int imaginary;
}

Complex add( Complex A, Complex B )
{
	Complex C;

	C.real = A.real + B.real;
	C.imaginary = A.imaginary + B.imaginary;

	return C;
}

Complex subtract( Complex A, Complex B )
{
	Complex C;

	C.real = A.real - B.real;
	C.imaginary = A.imaginary - B.imaginary;

	return C;
}

void showValue( Complex A )
{
	writeln( "%d + %di", A.real, A.imaginary );
}


main.d:
module main;

import std.stdio;

import complex;

void main()
{

	Complex A;
	Complex B;

	A.real = 5;
	A.imaginary = 6;

	B.real = 2;
	B.imaginary = 9;

	Complex C;
	Complex D;

	C = add( A, B );
	D = subtract( A, B)/>;

	showValues(A);
	showValues(B)/>;
	showValues(C);
	showValues(D);

}



When I attempt to compile main.d on the Ubuntu command prompt gdc compiler I recieve the following two errors:

main.d:13: identifier expected following '.', not 'real'
main.d:16: identifier expected following '.', not 'real'

Is the compiler simply not reading from the complex.d module? What would be the correct way to import the complex.d module?

Is This A Good Question/Topic? 0
  • +

Replies To: D Programming - How do you go about importing code modules?

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2118
  • View blog
  • Posts: 3,244
  • Joined: 21-June 11

Re: D Programming - How do you go about importing code modules?

Posted 16 September 2012 - 11:09 AM

I don't know anything about D, but I don't think the problem is related to your import statement.

The error message makes it sound as if real is a keyword and simply can't be used as the name of a variable. Try calling it something else.
Was This Post Helpful? 1
  • +
  • -

#3 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: D Programming - How do you go about importing code modules?

Posted 17 September 2012 - 03:44 PM

Yep 'real' is a keyword for the largest floating point type on the architecture(generally 80-bit/10 bytes). Every thing else should be fine.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1