Jump to content
  • Advertisement
Sign in to follow this  
luasitdown

why add a declaration in a class?

This topic is 4828 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
What, you mean like this?

class Classy
{
void function();
}


You can implement it later on. Like this:


void Classy::function()
{
..do whatever..
}


Usually that first part is in a .h file and the second part is in the .cpp file.

Share this post


Link to post
Share on other sites
if you place the declaration and the implementation into the header file the compiler will inline it(though i don tknow if that is compiler dependent)


if your class is templated you needto put the implementation into the header anyways

usually i place the implementation of library classes into the header

if the class is part of a program i placeit into the source file
small functions however are left in the header so the compiler can inline them

Share this post


Link to post
Share on other sites
no no no.
I mean :

class A
{
init();
parent();
destroy();
....
};

A::init()
{...}
A::parent()
{...}
but no destroy defination.maybe derived class will have the defination.
but class A has NO destroy() implementation.

Share this post


Link to post
Share on other sites
I believe that's perfectly valid. Just like:


#include <stdio.h>

int addTwoNumberTogetherVeryVeryQuickly(int a, int b);

int main(int argc,char **argv)
{
puts("Ha ha. Fooled you.");
return 0;
}


should compile and run fine. I did have some speed problems doing this, but that was in Assembler years ago, so I avoid it like the plague.

It's just a header file. It's just telling the computer what to expect to see. It may or may not see it, but it's able to understand it when it does.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!