Page 1 of 1

Creating Classes and functions

Posted: Thu Apr 06, 2006 6:54 pm
by Strong99
I have created an own class with functions, only when i call those functiosn it says

Code: Select all

d:\MMORPG\Code\Server\main.cpp(43): error C2352: 'RPG_calls::RPG_go: illegal call of non-static member function
In the header:

Code: Select all

class RPG_calls
{
public:
	void RPG_go(char*calls)
};
In the .cpp:

Code: Select all

void RPG_calls::RPG_go(char*calls)
{

}

Posted: Thu Apr 06, 2006 7:05 pm
by Aukecomps
...

Posted: Thu Apr 06, 2006 7:06 pm
by Ced666
It's because you are calling a function of a class directly. You first need to declare an instance of the class and work with that.

Code: Select all

RPG_calls MyClass;
MyClass.RPG_go("Test");
And by the way, what are you trying to do here ?
I strongly suggest you read some books about programation because this is really the basics of programing.

And, honnestly, if I were you, I would first start with simple programs ! Like a pong or a tetris (and you will already see that it is REALLY extremly difficult for a beginner). A MMORPG is something that takes several years for a team of professionals to develop. So, you, as a beginner and amateur, don't even imagine the time it will take. Do you have enough time ? One or two centuries ? Hope that medicine will do some progress soon :wink:
I don't want to be mean or to destroy your hope, but MMORPG are for now the more complex games to develop. And, if you even don't know how to use a class, that's completely absurd. Programming is also something that takes time (it's like learning music or sport), it is difficult and long.
This is just an advice, don't take it wrong.

Posted: Thu Apr 06, 2006 7:12 pm
by Aukecomps
...

Posted: Thu Apr 06, 2006 7:23 pm
by Ced666
but is it too less to be able to program something difficult?
Are you 'fluent' with the concepts of OOP (oriented-object programming), things like polymorphism, design patterns,... ? I believe that all these things are required whenever you want to do something more elaborate than a pong (and even in a pong, it is very very usefull).

A lot of people look at MMORPG like a game in which you can move a character and fight and that's it, but they don't sey what's beyond this. It looks easy to do but it's not at all. Did you even think of how pathfinding works ? How the AI is managed? All these things that needs to be implemented and that are not so easy to do (specifically for AI).
It requires not only an perfect knowledge of what you call the 'grammar manual' but a analytical mind in how you are gonna solve complex algorithm and how to solve 'architectural' problems (how you are gonna arrange your classes).
I have more or less 5 years of programming experience (as professional) and I still find that I have a lot of things to learn and I won't be able do to a complete MMORP being the only programmer.

Posted: Thu Apr 06, 2006 7:37 pm
by Aukecomps
...

Posted: Thu Apr 06, 2006 7:44 pm
by Xaron
Ced666 is right. strong99, I'm not sure anymore, that a MMORPG is a good starting project. ;)

Regarding your compiler error: You could make your RPG_go method static:

In your header declare:

Code: Select all

public:
  static void RPG_go(char* calls);
But this should only be done if it's really necessary. Sometimes this is useful. But don't wonder, you can't deal with member variables then, cause of the missing instance of the class. ;)

Regards - Xaron

Posted: Thu Apr 06, 2006 7:48 pm
by Strong99
In PHP or ASP you can call those classes different you know...

Posted: Thu Apr 06, 2006 7:55 pm
by Xaron
Yes, and there are no classes in the good old pascal. Lisp and Prolog are different, too. ;)

Regards - Xaron

Posted: Fri Apr 14, 2006 7:11 pm
by Jay
this whole class cannot exist because it is impossible to make an instance of the class, because it doesn't have any member variables.

a class needs the following:
-at least one member variable

also, a class can have member functions that operate with the member variables.

When there are only functions in a class it is sometimes better to get rid of that class and make it a namespace instead.

namespace RPG_calls
{
void RPG_go(char* calls);
};

void RPG_calls::RPG_go(char*calls)
{
;
};

that way you will be calling the function simply by

RPG_calls::RPG_go("Test");
->A namespace is like a class/structure but without member variables


As for a MMORPG - a RPG is difficult enough already...

I hope this helps.

Posted: Fri Apr 14, 2006 10:36 pm
by JP
Xaron wrote:Yes, and there are no classes in the good old pascal. Lisp and Prolog are different, too. ;)

Regards - Xaron
Prolog is evil! :shock: