![](/i/fill.gif) |
![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Darren New <dne### [at] san rr com> wrote:
> Correct. I was also pointing out that they get initialized to the type's
> version of zero, whatever that might be. (I.e., pointers may not have
> all zero bits in them; they get initialized to null instead.) Rarely can
> you see this difference. :-)
Actually it's possible to invoke the "default initialization" for any
type at any point in C++. For example if you do this:
int i = int();
the 'i' variable will be default-initialized with the "zero" value for
the type in question (which, in this case, is the integer 0).
One might ask what's the point. It's actually useful when you don't
know what the type actually is. This happens eg. with templates. You
could have, for example, this:
template<typename Type>
void foo()
{
Type i = Type(); // Default-initialize i, even if it's a basic type
...
}
Although mostly it's useful in situations where you want to create a
default-initialized temporary, for example in code like this:
someVector.push_back(Type());
That will work even if 'Type' is an int, a double or a pointer.
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
> Which timezone is that then?
PST. (California.)
- Slime
[ http://www.slimeland.com/ ]
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Slime wrote:
>> Which timezone is that then?
>
> PST. (California.)
You're Californian?
Wow... suddenly a whole lot of POV-Ray stuff makes way more sense... ;-)
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Copy...constructor...? x_x
Heh. And I thought figurating out the difference between a const pointer
and a pointer to a const was hard!
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Invisible wrote:
> Copy...constructor...? x_x
Pointers to members?
OK, maybe I should stop reading now. :-/
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Invisible <voi### [at] dev null> wrote:
> Copy...constructor...? x_x
Usually you don't need copy constructors unless you have pointers as
member variables of your class and you explicitly allocate memory to
them with 'new'. But we don't do that, do we? ;)
If you want a quick crash course on copy constructing when the class
allocates memory explicitly, check this:
http://warp.povusers.org/c++test/
(There are actually a few other situations where a copy constructor is
mandatory for a class to work properly, but they are slightly advanced
stuff.)
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Invisible <voi### [at] dev null> wrote:
> Pointers to members?
You don't need them.
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Warp wrote:
> Invisible <voi### [at] dev null> wrote:
>> Pointers to members?
>
> You don't need them.
That's what I was pretty much hoping, yeah.
Looks like it would only be useful for some pretty obscure situations...
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Warp wrote:
> Invisible <voi### [at] dev null> wrote:
>> Copy...constructor...? x_x
>
> Usually you don't need copy constructors unless you have pointers as
> member variables of your class and you explicitly allocate memory to
> them with 'new'. But we don't do that, do we? ;)
Heh. I get the impression that most of the stuff I'm reading about now
is stuff that "you won't normally need". ;-)
(E.g., apparently you can overload the "->" operator... GAH! >_< OK, I
am *so* not trying that out!)
Anyway, the main reason I haven't written a Third C++ Program yet is
that I'm trying to think of something I actually want to write that's
implementable without automatic memory management...
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Invisible <voi### [at] dev null> wrote:
> Warp wrote:
> > Invisible <voi### [at] dev null> wrote:
> >> Pointers to members?
> >
> > You don't need them.
> That's what I was pretty much hoping, yeah.
> Looks like it would only be useful for some pretty obscure situations...
They are useful in certain situations, but those situations are so rare
and usually so advanced, that even very experienced C++ programmers basically
never need them.
I once created a command-line parameter interpreter which was used like
this (extremely simplified):
class MyCLI: public CommandLineInterpreter
{
void inputFile() { ... }
public:
MyCLI()
{
// registerCLParameter() is a function in the base class.
registerCLParameter("input", &inputFile);
}
};
Basically this meant that when the interpreter encountered the command-line
parameter "-input", it would call the 'inputFile()' method I defined above.
This uses method pointers.
(The actual implementation is quite complicated because there are some
issues about a base class calling a derived class method through a method
pointer, but with template magic it's possible to do this portably and
safely.)
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |