By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,837 Members | 1,667 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,837 IT Pros & Developers. It's quick & easy.

struct problem

P: n/a
would someone please be so kind as to explain:

Jul 22 '05 #1
Share this Question
Share on Google+
16 Replies


P: n/a
would someone please be so kind as to explain:
struct Vertex
{
Vertex(){}
Vertex(float x, float y, float z,
float nx, float ny, float nz, float u, float v)
{
_x = x; _y = y; _z = z;
_nx = nx; _ny = ny; _nz = nz;
_u = u; _v = v;
}

float _x, _y, _z, _nx, _ny, _nz, _u, _v;

static const DWORD FVF;
};

what on earth is this:?!?!?!

Vertex(){}
Vertex(float x, float y, float z,
float nx, float ny, float nz, float u, float v)
{
_x = x; _y = y; _z = z;
_nx = nx; _ny = ny; _nz = nz;
_u = u; _v = v;
}

is vertex(){} a function? a variable. Could someone at least give me a name
as to what's going on here so i know what to look for?

cheers
dave

Jul 22 '05 #2

P: n/a
In article <3f******@dnews.tpgi.com.au>,
Dave <da**********************************@hotmail.co m> wrote:
would someone please be so kind as to explain:
struct Vertex
{
Vertex(){}
Vertex(float x, float y, float z,
float nx, float ny, float nz, float u, float v)
{
_x = x; _y = y; _z = z;
_nx = nx; _ny = ny; _nz = nz;
_u = u; _v = v;
}

float _x, _y, _z, _nx, _ny, _nz, _u, _v;

static const DWORD FVF;
}; [snip]is vertex(){} a function?


It's a constructor that takes no arguments/parameters, and does nothing.
It allows you to declare a variable of type Vertex without specifying
values for the data:

Vertex thisVertex;

in which case all the data members are default-initialized. In this case,
the data members are all floats, so they are not initialized at all and
contain whatever bit-patterns happened to be in those memory locations.

If you define no constructors at all, the compiler generates such a
default constructor for you automatically. However, if you define any
constructors of your own (as is the case here), you must define the
default constructor, too, if you want one.

--
Jon Bell <jt*******@presby.edu> Presbyterian College
Dept. of Physics and Computer Science Clinton, South Carolina USA
Jul 22 '05 #3

P: n/a
Vertex(){} is the default constructor. It is called every time an object of
Vertex is declared with no default parameters.

e.g.,
Vertex v1; \\ Vertex() is called
Vertex v2(0,0,0,0,0,0,0,0); \\ the second Vertex constructor is called.

Denver.

"Dave" <da**********************************@hotmail.co m> wrote in message
news:3f******@dnews.tpgi.com.au...
would someone please be so kind as to explain:
struct Vertex
{
Vertex(){}
Vertex(float x, float y, float z,
float nx, float ny, float nz, float u, float v)
{
_x = x; _y = y; _z = z;
_nx = nx; _ny = ny; _nz = nz;
_u = u; _v = v;
}

float _x, _y, _z, _nx, _ny, _nz, _u, _v;

static const DWORD FVF;
};

what on earth is this:?!?!?!

Vertex(){}
Vertex(float x, float y, float z,
float nx, float ny, float nz, float u, float v)
{
_x = x; _y = y; _z = z;
_nx = nx; _ny = ny; _nz = nz;
_u = u; _v = v;
}

is vertex(){} a function? a variable. Could someone at least give me a name as to what's going on here so i know what to look for?

cheers
dave

Jul 22 '05 #4

P: n/a

hmmm ok so vertex() is understandably a constructor. What, then, is the
purposes of the braces afterwards?
Also, what exactly is this:

{
_x = x; _y = y; _z = z;
_nx = nx; _ny = ny; _nz = nz;
_u = u; _v = v;
}
As far as I know, you can't declare variables in a class or struct. This
seems to be a definition rather than a declaration.
What is it actually doing?

cheers
dave
Jul 22 '05 #5

P: n/a
In article <3f******@dnews.tpgi.com.au>,
Dave <da**********************************@hotmail.co m> wrote:

hmmm ok so vertex() is understandably a constructor. What, then, is the
purposes of the braces afterwards?
That's the body of the constructor, which is empty, because it does
nothing.
Also, what exactly is this:

{
_x = x; _y = y; _z = z;
_nx = nx; _ny = ny; _nz = nz;
_u = u; _v = v;
}


That's the body of *that* constructor, which is not empty.

You can define the bodies of constructors and member functions either in
the class/struct definition, or separately. The following two versions of
your code accomplish the same thing:

//--- version A (your original version)

struct Vertex
{
Vertex(){}
Vertex(float x, float y, float z,
float nx, float ny, float nz, float u, float v)
{
_x = x; _y = y; _z = z;
_nx = nx; _ny = ny; _nz = nz;
_u = u; _v = v;
}

float _x, _y, _z, _nx, _ny, _nz, _u, _v;

static const DWORD FVF;
};

//--- version B ---------------------------------------------------

struct Vertex
{
Vertex();
Vertex(float x, float y, float z,
float nx, float ny, float nz, float u, float v);
float _x, _y, _z, _nx, _ny, _nz, _u, _v;
static const DWORD FVF;
};

// define the bodies of the constructors separately for version B

Vertex::Vertex()
{
}

Vertex::Vertex (float x, float y, float z,
float nx, float ny, float nz, float u, float v)
{
_x = x; _y = y; _z = z;
_nx = nx; _ny = ny; _nz = nz;
_u = u; _v = v;
}

--
Jon Bell <jt*******@presby.edu> Presbyterian College
Dept. of Physics and Computer Science Clinton, South Carolina USA
Jul 22 '05 #6

P: n/a
Wow! I never knew you could do that. Defining a constructor in the
definition? incredible.
thanks so much for your kind help.

dave :)
Jul 22 '05 #7

P: n/a

"Dave" <da**********************************@hotmail.co m> wrote in message
news:3f******@dnews.tpgi.com.au...
Wow! I never knew you could do that. Defining a constructor in the
definition? incredible.
thanks so much for your kind help.

dave :)


I guess it would be worth checking out any decent book like "Accelerated C++
by A. Koenig or Thinking C++ by B. Eckel for thinkg like this. Just keep in
mind that there are some subtleties for inlining constructors (covered in
Effective C++ Item 33 by Scott Meyers), which you might look up (but for the
moment this could be a little too advanced.)

Regards
Chris
Jul 22 '05 #8

P: n/a
I have the ebook Thinking In C++ 2nd Edition, and it's brilliant. The author
presents a whole new perspective of OOP i've never seen before. Beautifully
written, but still no substitute for a wise old c++ mentor. maybe one day ;)

thanks for all the help
dave
Jul 22 '05 #9

P: n/a
"Denver Dash" <dd***@sis.pitt.edu> wrote in message news:<bq**********@eeyore.INS.cwru.edu>...
Vertex(){} is the default constructor. It is called every time an object of
Vertex is declared with no default parameters.

e.g.,
Vertex v1; \\ Vertex() is called
Vertex v2(0,0,0,0,0,0,0,0); \\ the second Vertex constructor is called.

Denver.

"Dave" <da**********************************@hotmail.co m> wrote in message
news:3f******@dnews.tpgi.com.au...
would someone please be so kind as to explain:
struct Vertex
{
Vertex(){}
Vertex(float x, float y, float z,
float nx, float ny, float nz, float u, float v)
{
_x = x; _y = y; _z = z;
_nx = nx; _ny = ny; _nz = nz;
_u = u; _v = v;
}

float _x, _y, _z, _nx, _ny, _nz, _u, _v;

static const DWORD FVF;
};

what on earth is this:?!?!?!

Vertex(){}
Vertex(float x, float y, float z,
float nx, float ny, float nz, float u, float v)
{
_x = x; _y = y; _z = z;
_nx = nx; _ny = ny; _nz = nz;
_u = u; _v = v;
}

is vertex(){} a function? a variable. Could someone at least give me a

name
as to what's going on here so i know what to look for?

cheers
dave


chris i can't help you, but i take objection to Dave's apparent abrupt
reply which wasn't helpful in the slightest. To my mind Vertex is a
memeber function of type Vertex. I think chris was using a function
prototype and then the function definition. To my mind that seems the
most logical reading of the code.
Why can't some of you nerds just be pleasant for once, manners doesn't
cost a thing.
Jul 22 '05 #10

P: n/a
"muser" <ch**********@hotmail.com> wrote...
"Denver Dash" <dd***@sis.pitt.edu> wrote in message news:<bq**********@eeyore.INS.cwru.edu>...
Vertex(){} is the default constructor. It is called every time an object of Vertex is declared with no default parameters.

e.g.,
Vertex v1; \\ Vertex() is called
Vertex v2(0,0,0,0,0,0,0,0); \\ the second Vertex constructor is called.

Denver.

"Dave" <da**********************************@hotmail.co m> wrote in message news:3f******@dnews.tpgi.com.au...
would someone please be so kind as to explain:
struct Vertex
{
Vertex(){}
Vertex(float x, float y, float z,
float nx, float ny, float nz, float u, float v)
{
_x = x; _y = y; _z = z;
_nx = nx; _ny = ny; _nz = nz;
_u = u; _v = v;
}

float _x, _y, _z, _nx, _ny, _nz, _u, _v;

static const DWORD FVF;
};

what on earth is this:?!?!?!

Vertex(){}
Vertex(float x, float y, float z,
float nx, float ny, float nz, float u, float v)
{
_x = x; _y = y; _z = z;
_nx = nx; _ny = ny; _nz = nz;
_u = u; _v = v;
}

is vertex(){} a function? a variable. Could someone at least give me a

name
as to what's going on here so i know what to look for?

cheers
dave


chris i can't help you,


Who's "chris"? This conversation is between "Dave" and "Denver".
but i take objection to Dave's apparent abrupt
reply which wasn't helpful in the slightest.
I think you need to check in your objections and get the names
straight. Denver's reply is right on the money. Vertex() is
_in_fact_ the default constructor. Dave didn't give any reply,
so it can't really be abrupt or unhelpful.

And if you can't help, how do you know the other reply wasn't
helpful? You apparently have no idea what to say here.
To my mind Vertex is a
memeber function of type Vertex.
Well, a constructor is a member function, yes. What's your
point?
I think chris was using a function
prototype and then the function definition. To my mind that seems the
most logical reading of the code.
Why can't some of you nerds just be pleasant for once, manners doesn't
cost a thing.


So, they are _nerds_ all of a sudden? Why can't you jocks learn
not to call people names?

All in all, you probably ought to read the whole thread before even
thinking of replying. Your post seems rather out of place...
Jul 22 '05 #11

P: n/a
"Dave" <da**********************************@hotmail.co m> wrote in message
news:3f******@dnews.tpgi.com.au...
Wow! I never knew you could do that. Defining a constructor in the
definition? incredible.


Note that the implementation of all member functions can be included
within a class definition (not only constructors). These functions
are then *implicitly* declared as 'inline'.

Because of this, and for readability purposes, only very simple
functions should be inlined within the class definition.
hth -Ivan
--
http://ivan.vecerina.com


Jul 22 '05 #12

P: n/a
hmmm despite all the reading and research i've done, i never knew that! i
felt so stupid, i couldn't for the life of me figure out what was going on!

your help is most appreciated
cheers
dave
Jul 22 '05 #13

P: n/a
i'm a (*gasp*) NERD? oh no! my name is tainted forever!

;)
Jul 22 '05 #14

P: n/a

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:krOyb.274260$9E1.1428083@attbi_s52...
"muser" <ch**********@hotmail.com> wrote...
"Denver Dash" <dd***@sis.pitt.edu> wrote in message

news:<bq**********@eeyore.INS.cwru.edu>...

[SNIP]
chris i can't help you,


Who's "chris"? This conversation is between "Dave" and "Denver".


As I'm the only Chris who has replied to this thread (at least I think so)
he must be talking to me. I guess it's too bad that he can't help me though
I don't recall asking him for help.

[SNIP]
Why can't some of you nerds just be pleasant for once, manners doesn't
cost a thing.

[SNIP]

Somehow the use of "nerds" and "manners" in one sentence seems funny to
me...

Chris
Jul 22 '05 #15

P: n/a

"Dave" <da**********************************@hotmail.co m> wrote in message
news:3f******@dnews.tpgi.com.au...
Wow! I never knew you could do that. Defining a constructor in the
definition? incredible.


In this sense a constructor is simply a function, and you can define any
define to be "inline" by simply defining it right at the point of
declaration in the class definition.
Jul 22 '05 #16

P: n/a

"muser" <ch**********@hotmail.com> wrote in message
news:f9**************************@posting.google.c om...

chris i can't help you, but i take objection to Dave's apparent abrupt
reply which wasn't helpful in the slightest. To my mind Vertex is a
memeber function of type Vertex. I think chris was using a function
prototype and then the function definition. To my mind that seems the
most logical reading of the code.
Why can't some of you nerds just be pleasant for once, manners doesn't
cost a thing.


You are amazingly confused.
Jul 22 '05 #17

This discussion thread is closed

Replies have been disabled for this discussion.