You can't. You need to declare someting before you can use it. Same for variables and functions.
If you want you're main() on top of the file, you can use headerfiles to store the class declartion in.
In your first example you declare a function, then use it, then define it. In your second example you try to use a (member)function before declaring it, wich will result in an error. You can give the defention later:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
class A
{
public:
void function();
};
int main()
{
A myObject;
myObject.function();
}
void A::function()
{
cout<<"Hello World!";
}