digitalmars.D.learn - Class member functions
- Tommy (20/20) Sep 30 2005 In a C++ class I can put the body of a function outside the class
- JT (9/40) Sep 30 2005 class foo
- Tommy (5/13) Sep 30 2005 Is that supposed to mean "You have to write the function body into the
- JT (3/10) Sep 30 2005 well... yeah. D rules like that! you no longer have to hastle with
- Tommy (3/5) Oct 01 2005 OK, thanks, I see!
- Hasan Aljudy (2/23) Sep 30 2005 Yeah, and believe me, that's alot better!
- David L. Davis (33/53) Sep 30 2005 # // foo.d
- Tommy (5/6) Oct 01 2005 What's the difference between this and:
- Chris Sauls (8/16) Oct 01 2005 The difference is in symbol propagation. A public import (the default) ...
- Tommy (3/4) Oct 01 2005 Thanks for your answers! I think I understand it now.
In a C++ class I can put the body of a function outside the class definition, e.g.: // compiles fine as C++ class foo { public: void bar(); }; void foo::bar() // ERROR if compiled as D source { // do something } int main(){} //--- End of code In D, however, I get two errors on the marked line: - semicolon expected, not ':' - Declaration expected, not ':' What's the equivalent in D? Thanks, Tommy
Sep 30 2005
class foo { public: void bar() { // do something } } Tommy wrote:In a C++ class I can put the body of a function outside the class definition, e.g.: // compiles fine as C++ class foo { public: void bar(); }; void foo::bar() // ERROR if compiled as D source { // do something } int main(){} //--- End of code In D, however, I get two errors on the marked line: - semicolon expected, not ':' - Declaration expected, not ':' What's the equivalent in D? Thanks, Tommy
Sep 30 2005
In article <dhk7fe$2dqh$1 digitaldaemon.com>, JT says...class foo { public: void bar() { // do something } }Is that supposed to mean "You have to write the function body into the class definition, you simply can't put it outside the class definition"? Tommy
Sep 30 2005
well... yeah. D rules like that! you no longer have to hastle with headers..... Tommy wrote:Is that supposed to mean "You have to write the function body into the class definition, you simply can't put it outside the class definition"? Tommy
Sep 30 2005
OK, thanks, I see! Tommy In article <dhk9v1$2ft4$1 digitaldaemon.com>, JT says...well... yeah. D rules like that! you no longer have to hastle with headers.....
Oct 01 2005
Tommy wrote:In article <dhk7fe$2dqh$1 digitaldaemon.com>, JT says...Yeah, and believe me, that's alot better!class foo { public: void bar() { // do something } }Is that supposed to mean "You have to write the function body into the class definition, you simply can't put it outside the class definition"? Tommy
Sep 30 2005
In article <dhk5a7$2agq$1 digitaldaemon.com>, Tommy says...In a C++ class I can put the body of a function outside the class definition, e.g.: // compiles fine as C++ class foo { public: void bar(); }; void foo::bar() // ERROR if compiled as D source { // do something } int main(){} //--- End of code In D, however, I get two errors on the marked line: - semicolon expected, not ':' - Declaration expected, not ':' What's the equivalent in D? Thanks, TommyOutput: -------- C:\dmd>dmd foo.d C:\dmd\bin\..\..\dm\bin\link.exe foo,,,user32+kernel32/noi; C:\dmd>foo foo.bar called! C:\dmd> I don't think you can declare the class method outside of the class body itself, but I can tell you that D doesn't use the "::" (double semi-colons) like C++ does. Not sure if the example code above will be useful to you or not, but it's there just in case. ;) David L. ------------------------------------------------------------------- "Dare to reach for the Stars...Dare to Dream, Build, and Achieve!" ------------------------------------------------------------------- MKoD: http://spottedtiger.tripod.com/D_Language/D_Main_XP.html
Sep 30 2005
In article <dhk8q2$2ep1$1 digitaldaemon.com>, David L. Davis says...What's the difference between this and: import std.stdio; By the way, I seem to remember it is called std.c.stdio, not std.stdio?! Tommy
Oct 01 2005
Tommy wrote:In article <dhk8q2$2ep1$1 digitaldaemon.com>, David L. Davis says...The difference is in symbol propagation. A public import (the default) in a module Foo is visible to any other module that imports Foo. A private import in Foo is hidden from any other module importing foo.What's the difference between this and: import std.stdio;By the way, I seem to remember it is called std.c.stdio, not std.stdio?!Actually, both of these modules exist. Module std.c.stdio is the old stdio.h from C. Module std.stdio is D's new writef()/writefln() functions and their file/function variations. See: http://digitalmars.com/d/phobos/std_stdio.html . -- Chris Sauls
Oct 01 2005
In article <dhm4ev$g00$1 digitaldaemon.com>, Chris Sauls says...[...]Thanks for your answers! I think I understand it now. Tommy
Oct 01 2005