Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of static class in C++?

Tags:

c++

I recently encountered the definition of static class in C++ while going through the source code of ns2 simulator:

static class TCPHeaderClass : public PacketHeaderClass {
public:
        TCPHeaderClass() : PacketHeaderClass("PacketHeader/TCP",
                         sizeof(hdr_tcp)) {
        bind_offset(&hdr_tcp::offset_);
    }
} class_tcphdr;

I have never encountered a static class in C++ before. What are the properties and uses of the same?

like image 239
Bruce Avatar asked Dec 06 '22 13:12

Bruce


1 Answers

That is an unusual syntax to declare a static instance of TCPHeaderClass called class_tcphdr, equivalent to

class TCPHeaderClass : public PacketHeaderClass {
public:
        TCPHeaderClass() : PacketHeaderClass("PacketHeader/TCP",
                         sizeof(hdr_tcp)) {
        bind_offset(&hdr_tcp::offset_);
    }
};

static TCPHeaderClass class_tcphdr;
like image 155
juanchopanza Avatar answered Dec 09 '22 15:12

juanchopanza