473,221 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,221 software developers and data experts.

struct problem

would someone please be so kind as to explain:

Jul 22 '05 #1
16 2518
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
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
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

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
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
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

"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
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
"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
"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
"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
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
i'm a (*gasp*) NERD? oh no! my name is tainted forever!

;)
Jul 22 '05 #14

"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

"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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: grant | last post by:
Hi All, I am pretty new to python and am having a problem intepreting binary data using struct.unpack. I am reading a file containing binary packed data using open with "rb". All the values are...
3
by: Emanuele Blanco | last post by:
Hi there, I just compiled a program that uses linked lists (needed it as an homework for my Programming course at University). It works flawlessly, even if I notice a thing. Here's my linked...
20
by: fix | last post by:
Hi all, I feel unclear about what my code is doing, although it works but I am not sure if there is any possible bug, please help me to verify it. This is a trie node (just similar to tree nodes)...
6
by: sathyashrayan | last post by:
#include<stdio.h> #include<stdlib.h> #include<string.h> struct tree { int data; struct tree *left,*right; }; void init(struct tree *node)
7
by: Urs Wigger | last post by:
In a C++ project, I have the following struct definition: struct GridModeDataT { double dVal1; double dVal2; double dVal3; long ...
0
by: Peter Demeyer | last post by:
I have this problem: 'pno' is a pointer to a struct of type PRINTER_NOTIFY_OPTIONS. This struct is holding another struct called 'not' (of type PRINTER_NOTIFY_OPTIONS_TYPE) which contains a couple...
4
by: DaHool | last post by:
Hi there !!! I browsed around the Internet in search for a solution of a little difficult problem i have in VB.NET.... However, i cannot find a suitable anwser anywhere, so i thought i'll give...
4
by: hobbes992 | last post by:
Howdy folks, I've been working on a c project, compiling using gcc, and I've reached a problem. The assignment requires creation of a two-level directory file system. No files have to be added or...
19
by: rmr531 | last post by:
First of all I am very new to c++ so please bear with me. I am trying to create a program that keeps an inventory of items. I am trying to use a struct to store a product name, purchase price,...
19
by: bowlderyu | last post by:
Hello, all. If a struct contains a character strings, there are two methods to define the struct, one by character array, another by character pointer. E.g, //Program for struct includeing...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.