would someone please be so kind as to explain: 16 2598
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
In article <3f******@dnews .tpgi.com.au>,
Dave <da************ *************** *******@hotmail .com> 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*******@pres by.edu> Presbyterian College
Dept. of Physics and Computer Science Clinton, South Carolina USA
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 .com> wrote in message
news:3f******@d news.tpgi.com.a u... 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
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
In article <3f******@dnews .tpgi.com.au>,
Dave <da************ *************** *******@hotmail .com> 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*******@pres by.edu> Presbyterian College
Dept. of Physics and Computer Science Clinton, South Carolina USA
Wow! I never knew you could do that. Defining a constructor in the
definition? incredible.
thanks so much for your kind help.
dave :)
"Dave" <da************ *************** *******@hotmail .com> wrote in message
news:3f******@d news.tpgi.com.a u... 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 "Accelerate d 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
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
"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 .com> wrote in message news:3f******@d news.tpgi.com.a u... 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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 coming through
fine when using (integer1,) = struct.unpack('l', line)
except when line contains "carriage-return" "linefeed"
which are valid binary packed values. Error = unpack
string size dows not match format. It seems that
|
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 list declaration:
struct node {
float item;
struct node *next;
};
|
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) struct, I am storing an
array of 27 pointers and a void pointer that can point to anything.
typedef struct trieNode
{
struct trieNode *children; // The children nodes
void *obj; // The object stored
} TrieNode;
|
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)
|
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 lNumberOfPoints;
int bUseRegion;
enum ES_RegionType regionType;
| |
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 of 'normal' fields
and a pointer (called pFields) to an array of integers.
Now, when I make up everything (probably incorrectly), it compiles ok,
but when I execute this code, I get an error saying that pno is a
nullreference.
|
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 it
a try here...
Okay, here's the deal:
I am trying to read from unmanaged memory with a class type struct, this
|
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 deleted, however it must be initialized by a function during run-time to contain so many users which each contain so many directories of which each contain so many files. I've completed the program and have it running flawlessly without implementing...
|
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, sell price, and
a taxable flag (a Y/N char) and then write this all out to a file
(preferably just a plain old text file) and then read it in later so
that I can keep a running inventory. The problem that I am running
into is when I write to the...
|
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 character strings, test1.c
#include <stdio.h>
#define LEN 20
struct info {
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |