why add a declaration in a class?

Started by
3 comments, last by Nychold 18 years, 8 months ago
It is not virtual function.no defination in it. So the class can be instantiated? where does the declaration come to play?
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.
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
http://www.8ung.at/basiror/theironcross.html
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.
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.

This topic is closed to new replies.

Advertisement