How can assign a class value to another nested classes in C++ - c++

this is the first time to ask my question on Stackoverflow. my qustion is i got this message when i trying to run this code:
object.h
#ifndef __NCTUNS_nslobject_h__
#define __NCTUNS_nslobject_h__
#include <stdio.h>
#include <event.h>
//---------------------------------------------------
#include <cstdlib> //srand()
#include <iostream> //cout
#include <ctime> //time()
#include <cstring> //strcmp()
//#include "test.h" //testing functions
#include "RSA.h" //GenerateKeyPair()
#include "PrimeGenerator.h" //Generate()
//#include <stdio.h>
#include <stdlib.h>
#include <sstream>
#include <string>
//---------------------------------------------------
class MBinder;
struct plist {
u_int8_t pid;
struct plist *next;
};
struct MBlist {
u_int8_t portnum;
MBinder *sendt;
struct MBlist *next;
};
/*=========================================================================
Define Macros
=========================================================================*/
#define DISABLED 0x00
#define ENABLED 0x01
/*=========================================================================
Define Class ProtoType
=========================================================================*/
class NslObject {
private:
char *name_; /* Instance name */
const u_int32_t nodeID_; /* Node Id */
const u_int32_t nodeType_; /* Node type, eg: SWITCH, HOST.. */
u_int32_t portid_; /* port Id */
struct plist *MPlist_;
//const KeyPair newKeyPair;
public :
/* add for new structure engine*/
u_int32_t pdepth;
struct MBlist *BinderList;
u_int8_t PortNum;
//------------------------------------------------
static KeyPair newKeyPair ;
//static KeyPair *KeyPtr1 ;//= new KeyPair;
//------------------------------------------------
u_char s_flowctl; /* flow control for sending pkt */
u_char r_flowctl; /* flow control for receiving pkt */
MBinder *recvtarget_; /* to upper component */
MBinder *sendtarget_; /* to lower component */
NslObject(u_int32_t, u_int32_t, struct plist*, const char *);
NslObject();
virtual ~NslObject();
virtual int init();
virtual int recv(ePacket_ *);
virtual int send(ePacket_ *);
virtual int get(ePacket_ *, MBinder *);
virtual int put(ePacket_ *, MBinder *);
virtual ePacket_ *put1(ePacket_ *, MBinder *);
virtual int command(int argc, const char *argv[]);
virtual int Debugger();
inline void set_port(u_int32_t portid) {
portid_ = portid;
};
inline u_int32_t get_port() const {
return(portid_);
};
inline struct plist* get_portls() const {
return(MPlist_);
};
inline const char * get_name() const {
return(name_);
}
inline u_int32_t get_nid() const {
return(nodeID_);
}
inline u_int32_t get_type() const {
return(nodeType_);
}
//--------------------------------------------------------
static void Set_KeyPair(void);
// NslObject(const KeyPair &newKeyPair):
// newKeyPair(newKeyPair) {
// }
//NslObject( KeyPair &other, u_int32_t &N_ID, u_int32_t &N_Type) : newKeyPair(other),nodeID_ (N_ID),nodeType_ (N_Type) {}
/* Key(const BigInt &modulus, const BigInt &exponent) :
modulus(modulus), exponent(exponent) {
}*/
};
/* Added by CCLin to uniformly format
* debugging messages.
*/
#define NSLOBJ_DEBUG_STRING_HEAD() do { \
double sec; \
TICK_TO_SEC(sec, GetCurrentTime()); \
printf("%11.7f: [%03d]%s::%s: ", \
sec, get_nid(), \
getModuleName(this), __FUNCTION__); \
} while(0)
#endif /* __NCTUNS_object_h__ */
in Object.cc
void Set_KeyPair()
{
unsigned long int keyLength = 10;
//static KeyPair ADD(RSA::GenerateKeyPair(keyLength));
NslObject::newKeyPair (RSA::GenerateKeyPair(keyLength));
//NslObject::KeyPtr
//NslObject::newKeyPair;
}
so, my problem is when the compiler starts compiling it stops on this code :
NslObject::newKeyPair (RSA::GenerateKeyPair(keyLength));
and the appeared message is :
Error:
object.cc: In function ‘void Set_KeyPair()’:
object.cc:53: error: no match for call to ‘(KeyPair) (KeyPair&)’
so, how could i assign a generated keypair class value to NslObject::newKeyPair.
your helping is highly appreciated in advance & thank you .

If you want to assign it with a new value, then you need to use assignment:
NslObject::newKeyPair = RSA::GenerateKeyPair(keyLength);
Your code tries to call it like a function instead, with doesn't work because it isn't a functor.
(Also, you shouldn't use reserved names for your include guards.)

Related

Mosquitto: Use non-static callback function

I've running Mosquitto on my RPI4. But right know I only can set static callback functions. Is there a way to use class members?
I've tried to use std::bind to pass a class member function as callback:
main.cpp
#include <stdio.h>
#include <mosquitto.h>
#include "mqtt.h"
#include <string>
int main(int argc, char **argv)
{
MqttConnector * mqtt = new MqttConnector("piClient", "send", "rc", 1883, "localhost", 60);
mqtt->startClient();
return 0;
}
mqtt.h (only important parts
#include <mosquitto.h>
#include <string>
#include <stdio.h>
class MqttConnector
{
public:
MqttConnector(std::string id,
std::string sendTopic,
std::string receiveTopic,
int port,
std::string host,
int keepalive);
~MqttConnector();
void startClient();
private:
void messageCallback(struct mosquitto *mosq,
void *userdata,
const struct mosquitto_message *message);
struct mosquitto *mosqClient = NULL;
int keepalive;
int port;
std::string id;
std::string host;
std::string sendTopic;
std::string receiveTopic;
};
mqtt.cpp
#include "mqtt.h"
#include <stdio.h>
#include <string>
#include <string.h>
#include <mosquitto.h>
#include <functional>
using namespace std::placeholders;
MqttConnector::MqttConnector(std::string id, std::string sendTopic, std::string receiveTopic, int port, std::string host, int keepalive)
{
mosquitto_lib_init();
mosqClient = mosquitto_new(NULL, true, NULL);
if(!mosqClient){
fprintf(stderr, "Error: Out of memory.\n");
}
this->keepalive = keepalive;
this->id = id;
this->host = host;
this->port = port;
this->sendTopic = sendTopic;
this->receiveTopic = receiveTopic;
}
MqttConnector::~MqttConnector()
{
mosquitto_destroy(mosqClient);
mosquitto_lib_cleanup();
}
void MqttConnector::messageCallback(struct mosquitto *mosq, void *userdata, const struct mosquitto_message *message)
{
// I want to access class members like sendTopic / receiveTopic here
}
void MqttConnector::startClient()
{
// try to bind class members function
mosquitto_message_callback_set(mosqClient, std::bind(&MqttConnector::messageCallback, this, _1, _2, _3));
//other stuff
}
This gives me the following error while compiling:
cannot convert 'std::_Bind_helper<false, void (MqttConnector::*)(mosquitto*, void*, const mosquitto_message*), MqttConnector*, const std::_Placeholder<1>&, const std::_Placeholder<2>&, const std::_Placeholder<3>&>::type' {aka 'std::_Bind<void (MqttConnector::*(MqttConnector*, std::_Placeholder<1>, std::_Placeholder<2>, std::_Placeholder<3>))(mosquitto*, void*, const mosquitto_message*)>'} to 'void (*)(mosquitto*, void*, const mosquitto_message*)'
83 | mosquitto_message_callback_set(mosqClient, std::bind(&MqttConnector::messageCallback, this, _1, _2, _3));
Why doesn't it work?
Thanks!
This is a problem of using C-api from C++. What is the difference between a member function and a free function? When you provide a pointer to a member function a pointer to the class object is implicitly passed as the first parameter. Since C-api doesn't do that, but the problem is well known, the solution was introduced and it is called passing a context. Usually it is done through a void pointer. Functions that register callbacks usually take the pointer to the free function and a pointer to context. Then this pointer will be passed as one of the callback parameters.
In mosquitto case this context pointer is passed beforehand at the creation of a mosquitto object with mosquitto_new.
In order to make the callback function behave like a C function, we declare it static.
Inside the callback function we use static_cast to cast the void pointer to the object that we have provided.
mqtt.h
#include <mosquitto.h>
#include <string>
#include <stdio.h>
class MqttConnector
{
public:
MqttConnector(std::string id,
std::string sendTopic,
std::string receiveTopic,
int port,
std::string host,
int keepalive);
~MqttConnector();
void startClient();
private:
// make this function static
---->
static void messageCallback(struct mosquitto *mosq,
void *userdata,
const struct mosquitto_message *message);
struct mosquitto *mosqClient = NULL;
int keepalive;
int port;
std::string id;
std::string host;
std::string sendTopic;
std::string receiveTopic;
};
mqtt.cpp
#include "mqtt.h"
#include <stdio.h>
#include <string>
#include <string.h>
#include <mosquitto.h>
#include <functional>
using namespace std::placeholders;
MqttConnector::MqttConnector(std::string id, std::string sendTopic, std::string receiveTopic, int port, std::string host, int keepalive)
{
mosquitto_lib_init();
// provide apointer to this as user data
mosqClient = mosquitto_new(NULL, true, this);
---->
if(!mosqClient){
fprintf(stderr, "Error: Out of memory.\n");
}
this->keepalive = keepalive;
this->id = id;
this->host = host;
this->port = port;
this->sendTopic = sendTopic;
this->receiveTopic = receiveTopic;
}
MqttConnector::~MqttConnector()
{
mosquitto_destroy(mosqClient);
mosquitto_lib_cleanup();
}
void MqttConnector::messageCallback(struct mosquitto *mosq, void *userdata, const struct mosquitto_message *message)
{
// Use static cast to get pointer to your class object from userdata
MqttConnector *connector = static_cast<MqttConnector>(userdata);
connector->sendTopic;
}
void MqttConnector::startClient()
{
// static callback
mosquitto_message_callback_set(mosqClient, &MqttConnector::messageCallback);
// lambda callback
// beware, you can't use capture here
mosquitto_message_callback_set(&m, [/*no capture possible*/] (struct mosquitto *, void *userdata, const struct mosquitto_message *)
{
MqttConnector *connector = static_cast<MqttConnector>(userdata);
connector->sendTopic;
});
}

FreeRTOS CPP Function Pointer

I want to use a member function of a CPP Class for a FreeRTOS taskFunction.
Here is my initial solution
#ifndef TaskCPP_H
#define TaskCPP_H
#include "FreeRTOS.h"
#include "task.h"
template<typename T>
class TaskBase {
protected:
xTaskHandle handle;
void run() {};
public:
static void taskfun(void* parm) {
static_cast<T*>(parm)->run();
#if INCLUDE_vTaskDelete
vTaskDelete(static_cast<T*>(parm)->handle);
#else
while(1)
vTaskDelay(10000);
#endif
}
virtual ~TaskBase() {
#if INCLUDE_vTaskDelete
vTaskDelete(handle);
#endif
return;
}
};
#endif /* __TaskCPP_H__ */
#ifndef HTTPSERVER_H_
#define HTTPSERVER_H_
#include "TaskBase.h"
#include <string.h>
#include "lwip/opt.h"
#include "lwip/debug.h"
#include "lwip/stats.h"
#include "lwip/tcp.h"
#include "lwip/api.h"
#include "lwip/ip_addr.h"
class HttpServer;
class HttpServer : public TaskBase<HttpServer> {
public:
HttpServer();
virtual ~HttpServer();
void run();
void listen(ip_addr *address, uint8_t port);
void print();
protected:
char taskName[50];
ip_addr address;
uint8_t port;
};
#endif /* HTTPSERVER_H_ */
#include "HttpServer.h"
HttpServer::HttpServer()
{
}
void HttpServer::listen(ip_addr *address, uint8_t port) {
char buf[16];
sprintf(taskName, "%s_%d\r\n", ipaddr_ntoa_r(address, buf, 16), port);
DEBUGOUT("ADDRESS Listen: %x\r\n", &taskName);
this->handle = sys_thread_new(this->taskName, &taskfun, NULL, DEFAULT_THREAD_STACKSIZE + 128, DEFAULT_THREAD_PRIO);
}
void HttpServer::run() {
while(1) {
print();
Board_LED_Toggle(LEDS_LED2);
vTaskDelay(configTICK_RATE_HZ / 14);
}
}
void HttpServer::print() {
DEBUGOUT("ADDRESS Listen: %x\r\n", &taskName);
}
HttpServer::~HttpServer() {
// TODO Auto-generated destructor stub
}
Now my Problem ist that the context is not the same inside the run function. Printing the memory location of taskName is different inside listen(...) and run(...)
My nasty suspicion is that doing a static_cast of the run function looses the class context? Am I wrong?
Is there any other idea to provide a static function pointer to freeRTOS of a Class member function?
Here are the missing functions. The main and the sys_thread_new which is a wrapper only.
int main(void) {
prvSetupHardware();
HttpServer server;
server.listen(IP_ADDR_ANY, 80);
/* Start the scheduler */
vTaskStartScheduler();
/* Should never arrive here */
return 1;
}
sys_thread_t sys_thread_new( const char *pcName, void( *pxThread )( void *pvParameters ), void *pvArg, int iStackSize, int iPriority )
{
xTaskHandle xCreatedTask;
portBASE_TYPE xResult;
sys_thread_t xReturn;
xResult = xTaskCreate( pxThread, ( signed char * ) pcName, iStackSize, pvArg, iPriority, &xCreatedTask );
if( xResult == pdPASS )
{
xReturn = xCreatedTask;
}
else
{
xReturn = NULL;
}
return xReturn;
}
I use something like this:
class MyClass{
public:
static void run( void* pvParams ){
((MyClass*)pcParams)->runInner();
}
void runInner(){
while ( true ){
// TODO code here
}
}
};
then pass pointer to an object when creating task
MyClass* x = new MyClass;
xTaskCreate( MyClass::run, taskName, stackDepth, (void*) x, taskPrio, taskHandle );
edit:
Assuming you want to use templates:
template<typename T>
void run ( T* p ){
((T*)p)->run();
}
class MyClass{
public:
void run(){
while ( true ){
// task code
}
}
}
then creating the task
MyClass* x = new MyClass;
xTaskCreate( run<MyClass>, taskName, stackDepth, x, taskPrio, taskHandle );
Edit:
You need to cast run to (void (*)(void*))
xTaskCreate( (void (*)(void*))run<MyClass>, taskName, stackDepth, x, taskPrio, taskHandle );

C++ undefined symbol: NullPointerException error returned from a shared library

I'm having some problems with my code. A shared library is causing an undefined symbol error that I just cannot figure out. All of the files are in the correct locations and the shared library builds successfully but upon executing the program it returns the bellow message.
The error message:
libsp.so: undefined symbol: _ZTIN4Poco20NullPointerExceptionE
From what I can see the problem is the Poco headers I use. The headers I got from an outside source and they should all work, I believe the error is caused by how I call these headers, but I might be wrong.
Bellow is the only code that uses Poco in the libsp library. And the code of the 4 header files I use. I've checked and rechecked and cannot find any issues but am still getting the undefined symbol exception.
File Spexec.cpp (libsp):
#include "../poco/Poco/Base64Encoder.h"
#include "../poco/Poco/DigestEngine.h"
#include "../poco/Poco/MD5Engine.h"
#include "../poco/Poco/Path.h"
using namespace std;
stringstream s_base;
Poco::Base64Encoder encoder(s_base);
Poco::Path path(data.name);
data.path = data.name.substr(0, data.name.length() - path.getFileName().length());
Poco::MD5Engine md5;
stringstream ss;
ss << data.created << data.name;
md5.update(ss.str());
data.name = Poco::DigestEngine::digestToHex(md5.digest());
}
File Base64Encoder.h:
#ifndef Foundation_Base64Encoder_INCLUDED
#define Foundation_Base64Encoder_INCLUDED
#include "Foundation.h"
#include <ostream>
namespace Poco {
class Foundation_API Base64Encoder:, public std::ostream
{
public:
Base64Encoder(std::ostream& ostr);
~Base64Encoder();
private:
Base64Encoder(const Base64Encoder&);
Base64Encoder& operator = (const Base64Encoder&);
};
} // namespace Poco
#endif // Foundation_Base64Encoder_INCLUDED
File DigestEngine.h:
#ifndef Foundation_DigestEngine_INCLUDED
#define Foundation_DigestEngine_INCLUDED
#include "Foundation.h"
#include <vector>
namespace Poco {
class Foundation_API DigestEngine
{
public:
typedef std::vector<unsigned char> Digest;
DigestEngine();
virtual ~DigestEngine();
void update(const void* data, std::size_t length);
void update(char data);
void update(const std::string& data);
virtual std::size_t digestLength() const = 0;
virtual void reset() = 0;
virtual const Digest& digest() = 0;
static std::string digestToHex(const Digest& bytes);
static Digest digestFromHex(const std::string& digest);
presentation
protected:
virtual void updateImpl(const void* data, std::size_t length) = 0;
private:
DigestEngine(const DigestEngine&);
DigestEngine& operator = (const DigestEngine&);
};
File MD5Engine.h:
#ifndef Foundation_MD5Engine_INCLUDED
#define Foundation_MD5Engine_INCLUDED
#include "Foundation.h"
#include "DigestEngine.h"
namespace Poco {
class Foundation_API MD5Engine: public DigestEngine
{
public:
enum
{
BLOCK_SIZE = 64,
DIGEST_SIZE = 16
};
MD5Engine();
~MD5Engine();
std::size_t digestLength() const;
void reset();
const DigestEngine::Digest& digest();
protected:
void updateImpl(const void* data, std::size_t length);
private:
static void transform(UInt32 state[4], const unsigned char block[64]);
static void encode(unsigned char* output, const UInt32* input, std::size_t len);
static void decode(UInt32* output, const unsigned char* input, std::size_t len);
struct Context
{
UInt32 state[4]; // state (ABCD)
UInt32 count[2]; // number of bits, modulo 2^64 (lsb first)
unsigned char buffer[64]; // input buffer
};
Context _context;
DigestEngine::Digest _digest;
MD5Engine(const MD5Engine&);
MD5Engine& operator = (const MD5Engine&);
};
}
File Path.h:
#ifndef Foundation_Path_INCLUDED
#define Foundation_Path_INCLUDED
#include "Foundation.h"
#include <vector>
namespace Poco {
class Foundation_API Path
{
public:
enum Style
{
PATH_UNIX, /// Unix-style path
PATH_WINDOWS, /// Windows-style path
PATH_VMS, /// VMS-style path
PATH_NATIVE, /// The current platform's native style
PATH_GUESS /// Guess the style by examining the path
};
typedef std::vector<std::string> StringVec;
Path();
Path(const char* path);
Path(const std::string& path);
protected:
void parseUnix(const std::string& path);
void parseWindows(const std::string& path);
void parseVMS(const std::string& path);
void parseGuess(const std::string& path);
std::string buildUnix() const;
std::string buildWindows() const;
std::string buildVMS() const;
private:
std::string _node;
std::string _device;
std::string _name;
std::string _version;
StringVec _dirs;
bool _absolute;
};

C++ preprocessor directive issue

I have a stream class with following functions :
void writeInt(int value); //old function
void writeInt(int value, char* lable); //new function
we've used the writeInt() old function in lot of places. without changing the existing usage
I tried to replace the old function with the new function using following:
#define writeInt(x) writeInt(x,#x)
but it still calls the old functions not the new functions!.
Update:(working test-case)
// IStream.h
#include <stdio.h>
class IWStream {
public:
IWStream(char* path);
virtual ~IWStream();
virtual void writeInt( int iValue, char* szlable= 0 );
private:
FILE* _file;
};
//DataObject.h
class DataObject {
public:
DataObject(int value);
virtual ~DataObject(){};
void writeData(IWStream *stream);
private:
int _value;
};
//DataObject.cpp
#include "DataObject.h"
#include "IStream.h"
#define writeInt(x) writeInt(x,#x)
DataObject::DataObject(int value)
{
_value = value;
}
void DataObject::writeData(IWStream *stream)
{
stream->writeInt(_value);
}
//main.cpp
int main(){
IWStream stream("D://test.txt");
DataObject data(10);
data.writeData(&stream);
return 0;
}

error: expected primary-expression before ‘)’ token

I have tried many times to solve this problem but i got nothing.
The main purpose of this code is saving pair keys (Public and Private) in nested class NslObject::KeyK or NewKeyPair1.
.cpp file
unsigned long int keyLength = 10;
//KeyPair ADD(RSA::GenerateKeyPair(keyLength));
NslObject::KeyK(RSA::GenerateKeyPair(keyLength));
typedef NslObject::KeyK NewKeyPair1;
NewKeyPair1(RSA::GenerateKeyPair(keyLength));
//NslObject::
Key OtmanK(NslObject::Get_PublicKey(NewKeyPair1));
.h file:
#ifndef __NCTUNS_nslobject_h__
#define __NCTUNS_nslobject_h__
#include <stdio.h>
#include <event.h>
//---------------------------------------------------
#include <cstdlib> //srand()
#include <iostream> //cout
#include <ctime> //time()
#include <cstring> //strcmp()
//#include "test.h" //testing functions
#include "RSA.h" //GenerateKeyPair()
#include "PrimeGenerator.h" //Generate()
//#include <stdio.h>
#include <stdlib.h>
#include <sstream>
#include <string>
//---------------------------------------------------
class MBinder;
struct plist {
u_int8_t pid;
struct plist *next;
};
struct MBlist {
u_int8_t portnum;
MBinder *sendt;
struct MBlist *next;
};
/*=========================================================================
Define Macros
=========================================================================*/
#define DISABLED 0x00
#define ENABLED 0x01
/*=========================================================================
Define Class ProtoType
=========================================================================*/
class NslObject {
private:
char *name_; /* Instance name */
const u_int32_t nodeID_; /* Node Id */
const u_int32_t nodeType_; /* Node type, eg: SWITCH, HOST.. */
u_int32_t portid_; /* port Id */
struct plist *MPlist_;
// static KeyPair NewKeyPair;
public :
/* add for new structure engine*/
u_int32_t pdepth;
struct MBlist *BinderList;
u_int8_t PortNum;
//------------------------------------------------
class KeyK {
private :
KeyPair Kk;
public:
KeyK( KeyPair D1): Kk(D1)
{}
const Key &GetPrivateKey() const
{
return Kk.GetPrivateKey();
}
const Key &GetPublicKey() const
{
return Kk.GetPublicKey();
}
//KeyK NewKeyPair ;
};
Key Get_PrivateKey(KeyK &K){
return K.GetPrivateKey();
}
Key Get_PublicKey(KeyK &K){
return K.GetPublicKey();
}
//static KeyPair *KeyPtr1 ;//= new KeyPair;
//------------------------------------------------
u_char s_flowctl; /* flow control for sending pkt */
u_char r_flowctl; /* flow control for receiving pkt */
MBinder *recvtarget_; /* to upper component */
MBinder *sendtarget_; /* to lower component */
NslObject(u_int32_t, u_int32_t, struct plist*, const char *);
NslObject();
virtual ~NslObject();
virtual int init();
virtual int recv(ePacket_ *);
virtual int send(ePacket_ *);
virtual int get(ePacket_ *, MBinder *);
virtual int put(ePacket_ *, MBinder *);
virtual ePacket_ *put1(ePacket_ *, MBinder *);
virtual int command(int argc, const char *argv[]);
virtual int Debugger();
inline void set_port(u_int32_t portid) {
portid_ = portid;
};
inline u_int32_t get_port() const {
return(portid_);
};
inline struct plist* get_portls() const {
return(MPlist_);
};
inline const char * get_name() const {
return(name_);
}
inline u_int32_t get_nid() const {
return(nodeID_);
}
inline u_int32_t get_type() const {
return(nodeType_);
}
//--------------------------------------------------------
};
so, the problem in this line in cpp file :
Key OtmanK(NslObject::Get_PublicKey(NewKeyPair1));
when i tried to compile this project, i got this Error message:
object.cc:87: error: expected primary-expression before ‘)’ token
please, help me.
when i tried to make a directed call for key class, the other problem was appeared such as :
unsigned long int keyLength = 10;
//KeyPair ADD(RSA::GenerateKeyPair(keyLength));
NslObject::KeyK(RSA::GenerateKeyPair(keyLength));
typedef NslObject::KeyK NewKeyPair1;
NewKeyPair1(RSA::GenerateKeyPair(keyLength));
//NslObject::
//Key OtmanK(NewKeyPair1.GetPublicKey());
std::string message = "othman Alkilany";
// NslObject::NewKeyPair.GetPrivateKey()
std::string cypherText = RSA::Encrypt( message, NewKeyPair1.GetPublicKey());
the Error Message is :
error: expected primary-expression before ‘.’ token
I guess your issue is in the second line here:
typedef NslObject::KeyK NewKeyPair1;
NewKeyPair1(RSA::GenerateKeyPair(keyLength));
Resolving the typedef you've essentially written the following:
NslObject::KeyK(RSA::GenerateKeyPair(keyLength));
So you can clearly see you're missing the variable name for this line.
To fix this, name the variable/object:
NewKeyPair1 somekeypair(RSA::GenerateKeyPair(keyLength));
However, I guess you misused the typedef anyway? Did you try to name that NewKeyPair1? Something like this:
NslObject::KeyK NewKeyPair1(RSA::GenerateKeyPair(keyLength));