Forward Declaration

Derek Parnell derek at nomail.afraid.org
Thu Mar 15 21:37:26 PDT 2007


On Fri, 16 Mar 2007 03:37:07 +0000 (UTC), Satish wrote:

> Hello D Programmers
> 
> As a C++ programmer I have written classes such as
> 
> class Object{
>   public:
>     Object(int value1);
> };
> 
> Object::Object(int value1){}
> 
> My terminology will be wrong here but I really enjoy separating the
> declaration and implementation of class members.

Why?

> Yes in C++ also allows such declaration:
> class Object{
>   public:
>     Object(int value1){return 100;}
>     long server(){
>      //several lines of code 1
>      //several lines of code 2
>      //several lines of code 3
>      //several lines of code 4
>     }
> };


What is the difference between ...

  class Object{
    public:
      Object(int value1){return 100;}
      long server(){
       //several lines of code 1
       //several lines of code 2
       //several lines of code 3
       //several lines of code 4
      }
  };


and

 class Object{
   public:
     Object(int value1);
     long server();
 };

 Object::Object(int value1){return 100;}
 long Object::server(){
      //several lines of code 1
      //several lines of code 2
      //several lines of code 3
      //several lines of code 4
     }



> Why doesn't 'D' allow to separate method definition and method implementation
> such as
> <
>      Object::Object(int value1){
>         //my implementation
>      }

Actually it does allow that style of coding ...

  // define (list) the methods to be implemented.
  interface XXX
  {
        long server();
  }

  // now implement them.
  class OBJect : XXX
  {
      long server() {
      //several lines of code 1
      //several lines of code 2
      //several lines of code 3
      //several lines of code 4
     }
   }

> 
> If becomes tough not hard to debug classes if/when there is closing curly
> bracket if it missing.
> 
> I seem to more time ensure that I don't miss any opening and closing braces.

Both styles have the same brace matching issue so I don't see
why you might think this is a problem with the D style.

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Justice for David Hicks!"
16/03/2007 3:29:56 PM



More information about the Digitalmars-d mailing list