473,386 Members | 1,819 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,386 software developers and data experts.

struct problem

would someone please be so kind as to explain:

Jul 22 '05 #1
16 2529
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.