Body-less method declaration

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2009
Posts: 3
Reputation: serban is an unknown quantity at this point 
Solved Threads: 0
serban serban is offline Offline
Newbie Poster

Body-less method declaration

 
0
  #1
Oct 23rd, 2009
Hello

I have seen the following method syntax and I am trying to understand how this works/or doesn't:

public class MyClass
{

public MyClass();

public MyClass(string param);
}

There is no implementation of the methods (constructors) and class is not declared virtual either...
Is this something new in C# 3.0 ???

Any ideas???

Thank you
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,210
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 572
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast
 
0
  #2
Oct 23rd, 2009
That doesn't compile in 3.5 and I think the error message answers your question:
  1. 'daniweb.MyClass.MyClass()' must declare a body because it is not marked abstract, extern, or partial
  2. 'daniweb.MyClass.MyClass(string)' must declare a body because it is not marked abstract, extern, or partial

Interfaces allow you to declare methods similarly but the method must have a return type:
  1. public interface ITest
  2. {
  3. void ITest();
  4. }

I suspect you were looking at partial class definitions.
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,039
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter
 
-1
  #3
Oct 23rd, 2009
Either that or the methods were abstract.
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,210
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 572
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast
 
0
  #4
Oct 23rd, 2009
Originally Posted by Rashakil Fol View Post
Either that or the methods were abstract.
You can't have abstract constructors since the child classes cannot implement constructors from an inherited class...

None of these are valid:
  1. public abstract class AbstractClass
  2. {
  3. abstract AbstractClass();
  4. }
  5. public abstract class AbstractClass2
  6. {
  7. AbstractClass2();
  8. }
  9. public class AbstractClass3
  10. {
  11. abstract AbstractClass3();
  12. }
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,039
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter
 
0
  #5
Oct 23rd, 2009
Originally Posted by sknake View Post
You can't have abstract constructors since the child classes cannot implement constructors from an inherited class...
Obviously I wasn't talking about his code example because the methods there were not marked abstract.
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 903
Reputation: DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough 
Solved Threads: 144
DdoubleD DdoubleD is offline Offline
Posting Shark

Note to self: why is this title field here?

 
1
  #6
Oct 24th, 2009
Originally Posted by serban View Post
Hello

I have seen the following method syntax and I am trying to understand how this works/or doesn't:

public class MyClass
{

public MyClass();

public MyClass(string param);
}

There is no implementation of the methods (constructors) and class is not declared virtual either...
Is this something new in C# 3.0 ???

Any ideas???

Thank you
Perhaps you saw some C++ code that looks like this, which in its simplest form, is very similar in appearance. In C++, this is called forward declaration. C# does not allow forward declarations.
Last edited by DdoubleD; Oct 24th, 2009 at 9:33 am.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC