thelamb 163 Posting Pro in Training

My experience in learning a language has always been doing.
Of course the learning-style differs per person but I can only give you my view.

From when I was young(I still am, but younger ;P) I was always in interested in programming, I tried to start a few times but simply gave up at some point because all I was doing was reading books. Then at some point I met a person who I had been chatting with for over a year in real life and from that point on she changed everything :P. She had an idea for a project that had to be done in C++ and told me that I should do it, so then we sat on the sofa and she told me: "What are you waiting for, start typing."

And since then I havn't stopped learning C++. Of course it will be hard in the beginning, but if you just read from books you wont become a pro. In my experience starting out with just the very basics is the best way, you really have to think about what you want to achieve with your code then and search for everything you need and step by step your understanding of the language AND of logic will grow.

thelamb 163 Posting Pro in Training

You can keep a pointer to a b1 object in the passenger class.
So when a passenger 'spawns' you set one of the building objects in the passenger class.

Then you can call p1.building->ComeGetMe();

I think the building should then take care of calling the elevator function, because only the building knows which elevators it has (because you have 2 building you probably also have 2 elevators). If later you expand with multiple elevators you can set sort of a 'position' in the passenger that you hand over to the ComeGetMe() function and then the building calls the correct ComeGetMe() function on the correct elevator class.

I hope that made sense.

thelamb 163 Posting Pro in Training

The same answer applies to that and is specific to the driver you are talking about.

If the driver only has one version, for Linux, then you probably wont run into any problems, if there exist different versions for different distros then you might run into problems, but in this case I guess you can only be sure by testing, maybe there aren't any differences that apply to you.

thelamb 163 Posting Pro in Training

That's not really how it should work. It is good that you include the entire project so that we CAN download and compile it entirely. But that shouldn't be necessary if you give us a clear description of the error and paste the code where the error is occurring (paste the function where the error is and any relevant code we might need to see). Then if this code isn't enough to solve the problem we will download the whole source and look at it.

No offense intended but if you ask your questions like this it only looks like you are asking for others to do your homework. So please copy/paste the error and relevant code (with code tags of course) and tell us a little what you think the error could mean, so that we can see that you have actually thought about it (this is the most important part). Right now we are completely in the dark about what you have tried, what the error is about and we even still need to fix the first 3 errors before we come to the point where we can start helping you?

thelamb 163 Posting Pro in Training

Why do you expect others to do your homework? This approach will never work out on these forums.

Instead show us that you have done some effort and explain what you are having problems with. You say you have fixed 4 out of 16 problems, that means all the other 12 errors you can't fix? Or did you stop trying when you couldn't fix the 5th error.

A better approach would be to paste the error you are getting and paste the code where the error occurs. Then write something what YOU think is wrong and show that you have actually thought about the problem, then we can give you a hint on how to solve the error.

After all you are in school to learn, not to let others do the work for you and copy it.

Salem commented: Well said +36
thelamb 163 Posting Pro in Training

What exactly are you doing, and what is the error?
Try to give information like that from the start, it will make it much easier for others to understand what you mean, and it avoids giving a solution that has nothing to do with what you are trying to do.

thelamb 163 Posting Pro in Training

First of all, you are not closing the 'fin' stream, but this is not the cause of your problems.

Let's check what is happening:
You create a Message object, which in its constructor opens a file and reads from it. After that the file is closed.
A second instance of Message is created, which opens the same text file again and reads from it.

The second instance will just start reading from the beginning of the file again.

** EDIT: Ok I just made a suggestion but when reading it again I realised it makes no sense... so here is a better version :P:

What you can do is promote the fin variable to a static member variable so that all of the objects you create share the same fin variable so that the second time you create an instance it will start reading where the first instance stopped.
Or, you can store a static member variable that defines how many lines have already been read, but I don't know if you can open a file and set the internal pointer at a certain 'offset', you'd have to read up on this.

So I suggest you read up on static member variables to see how you can use them for your problem.

thelamb 163 Posting Pro in Training

Ok sorry I misread your question then, I thought you were printing to the screen.

But indeed, I guess the best way to go is just compare with and without printing.

thelamb 163 Posting Pro in Training

It indeed depends on how the LPDIRECT3D9 is defined, normally you will find a structure definition like:

struct _MYSTRUCT 
{
[indent]int myInt;
string myString;
[/indent]
} myStruct, *pmyStruct;

And then (I think just as a matter of preference) you can define something like LPMYSTRUCT as a pointer to the myStruct.
I use this a lot because I like it more than having *, for example:

typdef unsigned long DWORD, *PDWORD;

will define DWORD as unsigned long and PDWORD as unsigned long pointer. Saves me typing and it's personally more clear to me where I'm using pointers.

kvprajapati commented: Good point. +10
thelamb 163 Posting Pro in Training

When I started out with c++ I did some projects on projecteuler.net. I was always printing my results(in a while loop) untill one day I didn't do this and was blown away by how much faster the calculation was. So if you're going to print a lot you should ask yourself how useful that will be because in my experience it significantly slowed down my algorithm, and I didn't do anything with the output.

thelamb 163 Posting Pro in Training

Just because it says line 211 doesn't mean that that is the exact position of the error. And what exactly doesn't make sense about this error?

The compiler was reading through your code and it reached the end, but there still was a { that you didn't close (every { needs to be closed by a }).

Did you even try to understand the error yourself before posting here or?

thelamb 163 Posting Pro in Training

This is not an error that comes up because of syntax errors in your code.

You shouldn't write the class implementation in the .h file, the compiler is expecting to find a cbaseclass.cpp file somewhere, but it doesn't.
So create a cbaseclass.cpp, include the .h file and copy/paste the implementation into this file.

thelamb 163 Posting Pro in Training

I didn't misunderstand you, I just gave a short, uncomplete example of how you might implement classes.

In my very first sentence I note that it is not needed to use C++ classes to implement these game classes, instead you probably would use structures to store the character-specific information. So no one is forcing you to use classes in this case.

thelamb 163 Posting Pro in Training

You don't NEED to implement the game's classes with C++ classes, but this is a typical case where object oriented programming(using classes) comes in handy.

There isn't a single-best way to something like this but if you decide to use C++ classes you could decide to make a:

- "common" class that holds all functions that every character has, like the amount of cash, and it would define the game class of this character(e.g. warrior).

Then for each game class you create a c++ class (maybe even this you could split into 1 common class that has functions like attack, drink potion and 1 class that inherits from this class and has the character-specific properties).

In short, there are many ways in which you could code this, if you're serious about learning C++ then you really should look at classes ;)

thelamb 163 Posting Pro in Training
void (*PHook)(void); // 1
PHook = (void*)(0x00131000); // 2
PHook(void) // 3
{
	cout << "Bye";
}

The first error is on line //3, you forget the return type of the PHook function.

But all-together what you are doing isn't going to work out, if you're looking at some easy way to hook have a look at Microsoft's Detours library, it provides an easy way for you to hook your functions.

thelamb 163 Posting Pro in Training

And give us some more information on what exactly isn't working, are there errors or?

Secondly, the way you use select() will only work with one socket, what if you want to have more clients connecting to your proxy? Select() returns the number of sockets that are ready, so if you check if ( selectb >= 1 ) it will resolve to true but you'll have no idea which socket is ready.

For this you need to check if your socket is still in the FD_SET after the select() call.

So basically:

int selectb = select(0,&OrigMC,NULL,NULL,&tiz);
if ( selectb >= 1 )
{
[indent]if( FD_ISSET( kSock, &OrigMC )
{
[indent]recv(kSock, buf, sizeof(buf), 0);  
send(Szocket,buf,sizeof(buf),0);    
[/indent]
}
[/indent]
}

Of course it still only checks kSock, but it's up to your imagination how to make it work for more sockets.

thelamb 163 Posting Pro in Training

You're question (to me) isn't very clear.

Can you show us what you have done so far (including a better explanation of what you think has to be done) and point out with what exactly you are having problems.

thelamb 163 Posting Pro in Training

It seems indeed that is what he is trying to accomplish.

However, RoninMastaFX when you think about this problem logically, there must be a better way than defining variables with all possible case-variations.

What I think you have in mind is this:
A user types in the string "pi" (or any of its case variation) and you 'replace' it with the variable pi (or any if its case variation). But this will never work out, you can't say the following:

const double pi = 3.1415926535;
string myString = "pi";
double myResult = 3*myString;

I think that is essentially what you are trying to do.

What you can do is comparing the input from the user with the string "pi" and then saying 'ok, we need to replace pi somewhere'

const double pi = 3.1415926535;
string myString = "pi";  // This is the user's input
if( myString == "pi" )
{
[indent]doublemyResult = 3 * pi;[/indent]
}

To avoid comparing myString with "pi", "Pi" and all other case variations you should decide to either make the users input string all lower-case and compare to "pi" or all upper case and compare to "PI" (be consistent in this).

I havn't looked exactly at your piece of code but that is the idea I got from your explanation, I hope it makes sense to you and that you can get further with it.

I just saw that you've pasted the entire code and I noticed …

thelamb 163 Posting Pro in Training

Also depends on how much you are printing. Using endl can significantly slow your code if you are printing alot.

As an example when I started out with c++ I did some exercises on projecteuler.net, constantly printing in a while loop, I was blown away when at some point I decided to use '\n', and the algorithm finished in a mere seconds as opposed to minutes.

athlon32 commented: It was a great post...a lot of help :D +1
thelamb 163 Posting Pro in Training

The std namespace isn't defined in a header that you need to include, the compiler knows where to find it without you specifying it, much like it knows what an int is, without you implicitly telling it.

So it will even depend on the compiler where exactly the std namespace is defined.

But honoustly, why are you so determined to use a class with the name std? If you ask me you are wasting your time. There are some generally accepted keywords that you should stay away from.

I know that is not the answer you are looking for, but I wouldn't know of a way to do this, and it seems to me it is just time wasted that you could spend on actually writing code. But of course I don't know your exact motivation.

Including iostream.h instead of iostream won't do you any good, the std namespace is defined without including anything. And as these '.h' headers aren't guaranteed to behave as defined by the standard, there isn't really a reason to ever use them.

thelamb 163 Posting Pro in Training

Your code works fine for me, except that you do not flush the input buffer, so the Remove function doesn't wait for my input on the getline call, it straight passes the getline (because there is 'garbage' in the input stream). After that the search returns my added item correctly.

Learn how to flush input streams here:
http://www.daniweb.com/forums/thread90228.html

thelamb 163 Posting Pro in Training
int main()
{
    int* a = new int[2];
    func(a);
    delete[] a;
}

void func( int* a )
{
    // Do something with a
}
thelamb 163 Posting Pro in Training

After the select() returns the sockets that have data waiting I run the 'recv' function in a thread, the data is also processed here so based on the data from recv it might be necessary to disconnect that client(== an action on one of the maps). And other threads will require actions on the maps aswell(like a list of all connected clients etc.).

Anyway I've implemented that now aswell and I'm quite happy with the result, thanks again ;)

thelamb 163 Posting Pro in Training

Thank you for help, I have included your implementation now and it makes a lot more sense ;).
An extra advantage is that I can now include thread safety a lot easier since all adding/reading happens in one place.

thelamb 163 Posting Pro in Training

What I'm more worried about is that I need a new map for every identifier to find the correct client object.
So atm there are 3 maps that all have 'CClient*' as a value but different keys(string, int etc.). There is no way to have this in 1 container?

Basically it woul be nice to have a structure as a key and that I can use 'map.find' and it will search the structure members for a match but I guess that is not possible or am I wrong?

thelamb 163 Posting Pro in Training

Hello all,

I am coding a client/server in C++ - everything is working so far but I was wondering if my approach is correct or if there is a better way of handling this:

In this version only 64 clients need to be able to connect, in a different application I will write in the future there really isn't a set limit, so please comment if you think my approach will cause serious problems when the number of clients grows.

The application consists of a few classes:
CListenServer - Listen for new connections and accept them.
CClient - contains functions like 'receive' and 'send'.

CListenServer uses select() to check if a new connection is available and accepts it if there is, also it checks all the connected client sockets to see if there is any data waiting for recv().

In the main code I keep a map that contains the socket number as key and a pointer to the client object as value (map<int, CClient*>).

So when CListenServer returns a list of sockets that have data waiting, I can find the correct client object by using map.find(socket) and call the recv function on this CClient.

In the CClient I store the following info of the client:
Socket
IP
GUID (the clients are connected to a game server aswell, the GUID is a unique identifier for each client that is written in the game server's logfile when a client …