-1

I'm using RakNet to create a program which involves networking. I however don't know how to define a typedef for a Packet. The function I am trying to get it working for is:

void UDP_ClientDisconnected(Packet *pPacket);

Packet needs to be a typedef for this function obviously, however I don't know how to do this? Thanks to anyone who offers a solution.

Edit:

void Connections::UpdateRakNetwork()
{
for(Packet = Peer ->Receive(); Packet; Peer ->DeallocatePacket(Packet), Packet = Peer ->Recieve())
{
    PacketID = GetPacketIdentifier(Pacekt);

    switch(PacketID)
    {

        case ID_DISCONNECTION_NOTIFICATION:
            UDP_ClientDisconnected(Packet);
            break;
    }

    Peer ->DeallocatePacket(Packet);
}
}

Information is passed from this Packet sorting also in Connections.cpp, to the .h file in order to allow me to access these features from other elements of the game. Therefore allowing me to call UDP_ClientDisconnected(..); from another file.

As of yet there is no errors with this part of the file but the .h declaration, with the "Packet is not a Type name" error. As the guy below suggested it might be the fact that I named something else packet therefore I renamed it RakPacket and gain the same error.

andyb
  • 43,435
  • 12
  • 121
  • 150
user1591117
  • 287
  • 2
  • 5
  • 13
  • `Packet` does not *obviously* need to be a `typedef`. Maybe you can explain why it needs to be one. – juanchopanza Jul 16 '13 at 20:35
  • @MadScienceDreams how should templates help out here? – user1810087 Jul 16 '13 at 20:37
  • I'm fairly sure Packet is an interface - and that you have to inherit from it. Look in the header file defining class Packet - see if it has virtual methods make a class which implements these virtual methods - and pass it as `pPacket`. – Iwan Aucamp Jul 16 '13 at 20:38
  • Because Visual Studio keeps moaning at me sayin when I hover over the error: "Connections::Packet" is not a type name. If its now this how should I define packet? – user1591117 Jul 16 '13 at 20:39
  • @Iwan Sorry I didn't understand that :( – user1591117 Jul 16 '13 at 20:40
  • please be more specific. whats the error? what's the line the error is happening? – user1810087 Jul 16 '13 at 20:40
  • void Connections::UpdateRakNetwork() { for(Packet = Peer ->Receive(); Packet; Peer ->DeallocatePacket(Packet), Packet = Peer ->Recieve()) { PacketID = GetPacketIdentifier(Pacekt); switch(PacketID) { case ID_NEW_INCOMING_CONNECTION: Packet_NewIncommingConnection(Packet); break; case ID_DISCONNECTION_NOTIFICATION: Packet_PlayerDisconnected(Packet); break; case ID_CONNECTION_LOST: Packet_ConnectionLost(Packet); break; } Peer ->DeallocatePacket(Packet); } } – user1591117 Jul 16 '13 at 20:46
  • Information is passed from the Type of packet to that function for further processing, this will be used to display things such as Steve has Joined the Server. – user1591117 Jul 16 '13 at 20:46
  • you also can edit your post. – user1810087 Jul 16 '13 at 20:47
  • from your previous answer, Packet seems to be a object (variable), not a class definition. – Amadeus Jul 16 '13 at 20:54
  • @user1591117 - I downloaded RakNet - cant find UDP_ClientDisconnected anywhere in the package - can you please indicate what header provides UDP_ClientDisconnected - and maybe pastbin it somewhere and give the link. – Iwan Aucamp Jul 16 '13 at 21:02
  • I just updated the post, sorry its late but my lectrics went out. Also the UDP_ClientDisconnected is a custom declared function in order to alllow me to access these packet statements from other files. – user1591117 Jul 16 '13 at 21:07
  • @TomasBadan so Packet needs to be a Class? – user1591117 Jul 16 '13 at 21:12
  • Maybe you should begin with some easier program in C++. It seems that you are not familiar with Oriented Object Programming in C++. Take a look at : http://www.cplusplus.com/doc/tutorial/ It is a good begginning... – Pierre Fourgeaud Jul 16 '13 at 21:23
  • @Pierre I've been doing fine upto this point, I havn't had to look at any tutorials as I have done some OOP before. This is what I'm stuck on and oncce its reolved and I know why. I can then continue. I have actually noticed I DO point it to a struct (RakNet::Packet *RakPacket I did alter it earlier and I still continue to get this error. If no solution is foind I will still continue with this – user1591117 Jul 16 '13 at 21:28
  • @user1591117 in the function declaration, `Packet` could be a class/struct, but it could also be a typedef to a builtin type (unlikely, but cannot be ruled out). In your `Connections::UpdateRakNetwork()` definition, `Packet` looks like the name of a variable. So it has a different meaning in the two code samples you have shown. – juanchopanza Jul 17 '13 at 07:41

2 Answers2

1

It seems that it is the solution :

void Connections::UpdateRakNetwork()
{
    RakNet::Packet *RakPacket = NULL;
//  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    for(RakPacket = Peer->Receive(); NULL != RakPacket; Peer->DeallocatePacket(RakPacket), RakPacket = Peer->Recieve())
//      ^^^^^^^^^                            ^^^^^^^^^                         ^^^^^^^^^   ^^^^^^^^^
    {
        RakNet::PacketID pID = GetPacketIdentifier(RakPacket);
//      ^^^^^^^^^^^^^^^^^^^^                       ^^^^^^^^^

        switch(pID)
        {

            case ID_DISCONNECTION_NOTIFICATION:
                UDP_ClientDisconnected(RakPacket);
//                                     ^^^^^^^^^
                break;
        }

        Peer->DeallocatePacket(RakPacket);
//                             ^^^^^^^^^
    }
}

I'm not helping you by giving you that. Again try to understand RakNet::Packet *RakPacket = NULL; and why we are not using the classname as a parameter of a function but the pointer to an object...

EDIT :

In response of the first comment :

In C++, an object is a region of storage with associated semantics. In the context of the object model of C++, the term object refers to an instance of a class. A class defines the characteristics of its instances in terms of members: data members (state) and member functions (methods or operations), and the visibility of these members to other classes. C++ is statically typed.

In this explanation you can replace the word class by struct. The only difference between both is the default access right to their members (private for class and public for struct) : What are the differences between struct and class in C++?.

Community
  • 1
  • 1
Pierre Fourgeaud
  • 14,290
  • 1
  • 38
  • 62
  • RakNet::Packet is an Object.. its a struct. – user1591117 Jul 16 '13 at 21:45
  • @user1591117 I would say it is a type. For example, `RakNet::Packet p` here p is an object of type `RakNet::Packet`. I edited my post for an explanation... – Pierre Fourgeaud Jul 16 '13 at 21:50
  • Okay... I'll do some reading up on this part however I seem to understand nost things I've since come accross. I actually have a working Game Engine I plugged into the Client and everything; I started this in order to just see how far I can get, and I was refusing to be beaten at Server Sided RakNet. Thanks btw :D. – user1591117 Jul 16 '13 at 21:59
-2

You can this easily by writing:

typedef Packet * pPacket;

After that you can create a pointer to a Packet object via:

pPacket somePacket(NULL);
somePacket = new Packet(...);
//etc...

Typedef's are great, but hiding pointers makes it unreadable. So if you really want to do that, you better have a good reason for this.

EDIT:

"Connections::Packet" is not a type name.

Make sure that you include the correct classes and libraries. Is that your only compiler error?

GlenDC
  • 23
  • 6
  • 1
    do you really think this will solve the problem if the function looks like `void UDP_ClientDisconnected(Packet *pPacket);`? – user1810087 Jul 16 '13 at 20:47
  • I trided changing it to – user1591117 Jul 16 '13 at 20:48
  • 1
    @itwasntpete. No probably not. But he asked how to do it and so I told him how. I don't think his problem is related to the typedef keyword in anyway. That's why I asked more questions. – GlenDC Jul 16 '13 at 20:50