Hi guys ,
i am very new to this language so can you tell me which style below function is showing in C++.

SmeConfigRnc::SmeConfigRnc(uint32_t rncId, uint16_t pc) : m_RncId(rncId), m_Pc(pc)
{   
    //Allocate userId
    m_UserId = SmeConfigMgr::GetInstance()->GetFromFreeUserIdPool();
    printf("Allocated for RNC, User Id=%d\n", m_UserId);
    //Allocate mtpSap
    m_MtpSapId = SmeConfigMgr::GetInstance()->GetFromFreeMtpSapIdPool();
    printf("Allocated for RNC, MTP SAP=%d\n", m_MtpSapId);
}

Dani AI

Generated

A few focused notes to complement 's explanation and highlight practical pitfalls that are easy to miss.

The member-initializer list is the right tool for direct initialization: it constructs members rather than default-constructing then assigning. That matters for const or reference members and for non-trivial types (avoids an extra construction). A common bug: the actual initialization order is the order members are declared in the class, not the order in the initializer list — keep the initializer list in the same order as the declarations to avoid surprises.

Prefer fixed-width types and safer output. Use the standard headers (<cstdint> / <cinttypes> or <inttypes.h>) so intent is clear, and avoid printf with a mismatched format specifier (passing a uint32_t to %d is undefined behavior). Example using iostream:

#include <iostream>
#include <cstdint>

std::cout << "Allocated for RNC, User Id=" << m_UserId << '\n';

Or, if printf is required, use the macros from <cinttypes>:

#include <cinttypes>
printf("Allocated for RNC, User Id=%" PRIu32 "\n", m_UserId);

On the SmeConfigMgr / singleton side (as noted by ): confirm the initialization is thread-safe and that the allocation call's return value is checked. Modern C++ (since C++11) guarantees thread-safe initialization for function-local statics; older code may need explicit locking. Prefer RAII for pooled resources: wrap an allocated ID in a small guard that returns it in its destructor so leaks are avoided if construction throws later.

Quick checklist for review:

  • Match initializer-list order to declaration order.
  • Use std::uint32_t/std::uint16_t and include <cstdint>.
  • Replace unsafe printf usage with std::cout or PRIu32 macros.
  • Ensure GetFromFree... return values are validated and IDs are returned in the destructor (RAII).

I'm not sure exactly what you're asking when you say
"can you tell me which style below function is showing in C++"

But I can answer the question in the topic title
"what is going on in this function?"

SmeConfigRnc::SmeConfigRnc(uint32_t rncId, uint16_t pc) : m_RncId(rncId), m_Pc(pc)
{   
    //Allocate userId
    m_UserId = SmeConfigMgr::GetInstance()->GetFromFreeUserIdPool();
    printf("Allocated for RNC, User Id=%d\n", m_UserId);
    //Allocate mtpSap
    m_MtpSapId = SmeConfigMgr::GetInstance()->GetFromFreeMtpSapIdPool();
    printf("Allocated for RNC, MTP SAP=%d\n", m_MtpSapId);
}

This line:

SmeConfigRnc::SmeConfigRnc(uint32_t rncId, uint16_t pc) : m_RncId(rncId), m_Pc(pc)

Is the constructor for a class called SmeConfigRnc.
The two parameters (rncId and pc) look as though they are user defined types (uint32_t and uint16_t) which are probably defined elsewhere using typedef statements.. (Otherwise they could be primitive types specific to the compiler being used to compile the program!)
Either way it looks as if they are a 32 bit unsigned integer and a 16 bit unsigned integer.

In the part of the constructor code which says:

: m_RncId(rncId), m_Pc(pc)

Two member variables ( m_RncId and m_Pc) are assigned the values passed into the constructor (i.e. the values of rncId and pc respectively)

The first line in the constructors body (after the comment):

m_UserId = SmeConfigMgr::GetInstance()->GetFromFreeUserIdPool();

This line is doing quite a lot.
SmeConfigMgr looks like it's probably a singleton (a class which can only have one instance in memory), the GetInstance() function will be a static member function of the SmeConfigMgr class which will return a pointer to the current instance of the SmeConfigMgr class.

Basically this line gets a pointer to the SmeConfigMgr class and then calls the GetFromFreeUserIdPool() method of SmeConfigMgr (which I assume returns some kind of int). m_UserId is then assigned the value returned by the call to SmeConfigMgr::GetFromFreeUserIdPool()

The printf statement (which is poor practice to use in a c++ app, std::cout should really be used!) prints a message to the console and shows the value of m_UserId.

Similarly:

m_MtpSapId = SmeConfigMgr::GetInstance()->GetFromFreeMtpSapIdPool();
    printf("Allocated for RNC, MTP SAP=%d\n", m_MtpSapId);

This time a pointer to the current instance of SmeConfigMgr is obtained using a call to SmeConfigMgr::GetInstance() and then the GetFromFreeMtpSapIdPool() method of SmeConfigMgr is called.
m_MtpSapId is assigned the value returned by the call to GetFromFreeMtpSapIdPool()

Finally a printf is used to print a message and the value of m_MtpSapId to the console.

I hope that is of some help!

Cheers for now,
Jason.

commented: Good post. +6
commented: Very Nice Description +8
commented: Nicely explained +3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.