I found out today that a declaration has a type and a name - a definition has a
type - a name - and a value.......so,
int x; a declaration and int x=2; a definition ( and a declaration),
but it is first a declaration because it first has a type (int), then a name (x)
Thomas Hruska <[EMAIL PROTECTED]> wrote: Robert Ryan wrote:
> thanks, I am looking at the books and trying to figure out the declarations
> and definitions
>
> Brett McCoy wrote: On Feb 17, 2008 11:51 PM,
> Robert Ryan wrote:
>
> > I guess that a declaration can be a definition,
> > since it is one in the same, true
> > int x; //declaration
> > int x = 5; //declaration and definition
>
> Don't just guess. Look it up! You've been given a list of books, and
> you can get the draft standards for free.
>
> -- Brett
> ----------------------------------------------------------
> "In the rhythm of music a secret is hidden;
> If I were to divulge it, it would overturn the world."
> -- Jelaleddin Rumi
The ANSI C++ Standard is going to give you definitive definitions. I
recommend reading section 3.1 of the ANSI C++ Standard. It is titled
"Declarations and definitions". And now for some horrible
copy-and-paste mangling from my draft copy of the ANSI C++ Standard into
an e-mail:
------------------------------------------
1 A declaration (clause 7) introduces names into a translation unit or
redeclares names introduced by previous declarations. A declaration
specifies the interpretation and attributes of these names.
2 A declaration is a definition unless it declares a function without
specifying the functions body (8.4), it contains the 3.1 Declarations
and definitions Basic concepts 26 extern specifier (7.1.1) or a
linkage-specification 27) (7.5) and neither an initializer nor a
function-body, it declares a static data member in a class definition
(9.4), it is a class name declaration (9.1), or it is a typedef
declaration (7.1.3), a using-declaration (7.3.3), or a
using-directive(7.3.4).
[ Example: all but one of the following are definitions:
int a; // defines a
extern const int c = 1; // defines c
int f(int x ) { return x+a ; } // defines f and defines x
struct S { int a; int b ; }; // defines S, S::a, and S::b
struct X { // defines X
int x; // defines non-static data member x
static int y; // declares static data member y
X (): x (0) { } // defines a constructor of X
};
int X::y = 1; // defines X::y
enum { up , down }; // defines up and down
namespace N { int d ; } // defines N and N::d
namespace N1 = N; // defines N1
X anX ; // defines anX
whereas these are just declarations:
extern int a; // declares a
extern const int c; // declares c
int f(int ); // declares f
struct S; // declares S
typedef int Int ; // declares Int
extern X anotherX ; // declares anotherX
using N::d; // declares N::d
end example ]
------------------------------------------
--
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197
*NEW* MyTaskFocus 1.1
Get on task. Stay on task.
http://www.CubicleSoft.com/MyTaskFocus/
To unsubscribe, send a blank message to .
Yahoo! Groups Links
---------------------------------
Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.
[Non-text portions of this message have been removed]