If i have the following class:
Then what does that last line mean?? What could be the reason for this..??Code:class cBlaat
{
public:
void SomeFunc();
};
typedef class cBlaat * LPBLAAT;
"typedef class cBlaat * LPBLAAT"
Printable View
If i have the following class:
Then what does that last line mean?? What could be the reason for this..??Code:class cBlaat
{
public:
void SomeFunc();
};
typedef class cBlaat * LPBLAAT;
"typedef class cBlaat * LPBLAAT"
It just makes LPBLAAT an alias for the type cBlaat*. The class keyword in the typedef is unnecessary.
[ Moved thread ]
Ok thanks, then i have another question about a class. Suppose i have the following code:
Why doesn't "cBlaat * blaat" work when i declare it outside of a function, but does it work when i declare it as "cBlaat blaat" ??Code:class cBlaat
{
public:
DoSomething();
};
cBlaat * blaat; //doesn't work
int main()
{
blaat->DoSomething();
return 0;
}
I just don't get what's so different about it...
It works, but looking at your sample code (which will not even compile), you probably tried to dereference the pointer when it did not point to an object (in this case, it is a null pointer).Quote:
Originally Posted by vivendi
To expand on what laserlight said...
The firstonly declares a pointer to a cBlaat object - it does not create an instance of the object - you only have an invalid pointer at this point.Code:cBlaat *blaat;
The secondactually creates an instance of the cBlaat object - so you actually have one of those objects existing and can operate on it.Code:cBlaat blaat;
Hope that helps.
Notice that it has static storage duration, hence it is zero initialised.Quote:
Originally Posted by ninja9578
What's the return type of cBlaat::DoSomething()? ;)Quote:
Originally Posted by rohshall
The function is also used, but never defined.
Remember that
Is undefined behavior, but stable on almost every compiler.Code:class foo {
void DoSomething(void);
};
void foo::DoSomething(void){
std::cout << "Hello World" << std::endl;
}
foo * bar;
main(){
bar -> DoSomething();
}
Also, why do statically declared pointers initialize to zero? Seems like a waste of a mov command to me. I always do this
If I want to know if the pointer has been initialized or not later. If I omit the zero, I don't care what it is.Code:foo * bar = 0;