error: expected primary-expression before ‘)’ token - c++

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));

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;
});
}

In function undefined reference c++

I get a strange error all the time.
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o:
In function _start: >(.text+0x20): undefined reference to main
/tmp/cc4ZqKzy.o:
In function `Sep::Building::Building(Sep::Field::FieldType, >std::__cxx11::basic_string, >std::allocator >, char, bool, bool, unsigned int, unsigned int):
Building.cpp:(.text+0x3c): undefined reference to Sep::Field::Field()
collect2:
error: ld returned 1 exit status
I read a lot with this problem but none had the same. I included all the headers and also added ifndef guards.
main.cpp:
#include "Field.h"
#include "Building.h"
namespace Sep
{
just some returns...
}
int main(int argc, char *argv[])
{
Sep::Building Haus(Sep::Field::FieldType::HOME,"HOME", 'H', true, true, 100, 100);
std::cout << "HAUS ABREV:" << Haus.getAbbrevationOnField() << '\n';
}
Field.h
#include <cstring>
#include <string>
#include <iostream>
#include <memory>
#ifndef FIELD_H
#define FIELD_H
namespace Sep
{
//----------------------------------------------------------------------------
// Field class, containing all needed information to create a Field object
//
class Field
{
public :
enum FieldType \
{GRASS, WATER, OBSTACLE, STREET, HOME, MARKET, CLINIC, TOWNHALL};
private:
FieldType type_;
std::string name_;
char abbrevation_;
bool buildable_;
bool destroyable_;
unsigned int build_cost_;
unsigned int destroy_cost_;
public:
//------------------------------------------------------------------------
// Field constructors & destructor
//
Field();
Field(FieldType type);
~Field() noexcept;
//------------------------------------------------------------------------
//getters
//
Field::FieldType getFieldType() const { return type_; };
const char getAbbrevationOnField() const { return abbrevation_; };
//------------------------------------------------------------------------
//setters
//
static std::string getName(FieldType type);
FieldType getType() const;//steht oben in getFiel3dType Z55
void setType(FieldType type){type_ = type;};
void setName(std::string name){name_ = name;};
void setAbbrevation(char abbrev){abbrevation_ = abbrev;};
void setBuildable(bool buildable){buildable_ = buildable;};
void setDestroyable(bool destroyable){destroyable_ = destroyable;};
void setBuildCost(int b_cost){build_cost_ = b_cost;};
void setDestroyCost(int d_cost){destroy_cost_ = d_cost;};
};
}
#endif //FIELD.H
Field.cpp
#include "Field.h"
#include <cstring>
#include <string>
#include <iostream>
#include <memory>
using Sep::Field;
//------------------------------------------------------------------------------
// Setter of the private FieldType type_ to the given param
//
// #param the type of field to get set
//
Field::Field(FieldType type)
{
type_ = type;
};
Field::~Field(){};
//------------------------------------------------------------------------------
// Checks the type of a given field, returns the name of type as string
//
// #param type, the type of the field to check
//
// #return string the name of the type of the checked field
//
std::string Field::getName(FieldType type)
{
switch (type)
{
case GRASS:
return std::string("Grass");
case WATER:
return std::string("Water");
case OBSTACLE:
return std::string("Obstacle");
case STREET:
return std::string("Street");
case HOME:
return std::string("Home");
case MARKET:
return std::string("Market");
case CLINIC:
return std::string("Clinic");
case TOWNHALL:
return std::string("Town Hall");
default:
return std::string("Unknown Field");
}
};
//------------------------------------------------------------------------------
// getters
//
// Getter from the private FieldType type_
//
// #param none
//
// #return the type of type_ as FieldType
//
Field::FieldType Field::getType() const
{
return type_;
};
Building.h
#ifndef BUILDING_H
#define BUILDING_H
#include "Field.h"
namespace Sep
{
class Building : public Field
{
private:
public:
Building(FieldType type, const std::string name, const char abbrevation, \
const bool buildable, const bool destroyable,\
const unsigned int b_cost, const unsigned int d_cost);
~Building();
};
}
#endif //BUILDING_H
Building.cpp
#include "Building.h"
#include "Field.h"
Sep::Building::Building(FieldType type, const std::string name, \
const char abbrevation, \
const bool buildable, const bool destroyable,\
const unsigned int b_cost, const unsigned int d_cost)
{
Sep::Field::setType(type);
Sep::Field::setName(name);
Sep::Field::setAbbrevation(abbrevation);
Sep::Field::setBuildable(buildable);
Sep::Field::setDestroyable(destroyable);
Sep::Field::setBuildCost(b_cost);
Sep::Field::setDestroyCost(d_cost);
};
Sep::Building::~Building(){};
Has anyone a idea? Cause I get this error often in this project but in other classes.
The strange thing is that it seems like, that the program compiles correctly but on the start I get this collect2: error: ld returned 1 exit status.
Thx
Field.cpp need to be changed, if don't want to used Field() constructor just put the definition of Field() constructor empty.
For examples:
Field.cpp
#include "Field.h"
#include <cstring>
#include <string>
#include <iostream>
#include <memory>
using Sep::Field;
//------------------------------------------------------------------------------
// Setter of the private FieldType type_ to the given param
//
// #param the type of field to get set
//
Field::Field(){
//empty constructor or can initialize type_ to default value.
}
Field::Field(FieldType type)
{
type_ = type;
};
Field::~Field(){};
//------------------------------------------------------------------------------
// Checks the type of a given field, returns the name of type as string
//
// #param type, the type of the field to check
//
// #return string the name of the type of the checked field
//
std::string Field::getName(FieldType type)
{
switch (type)
{
case GRASS:
return std::string("Grass");
case WATER:
return std::string("Water");
case OBSTACLE:
return std::string("Obstacle");
case STREET:
return std::string("Street");
case HOME:
return std::string("Home");
case MARKET:
return std::string("Market");
case CLINIC:
return std::string("Clinic");
case TOWNHALL:
return std::string("Town Hall");
default:
return std::string("Unknown Field");
}
};
//------------------------------------------------------------------------------
// getters
//
// Getter from the private FieldType type_
//
// #param none
//
// #return the type of type_ as FieldType
//
Field::FieldType Field::getType() const
{
return type_;
};
When you are trying to construct a Building, the Building::Building(...) constructor implicitly calls its base class constructor Field::Field() (since you did not specify which Field constructor you want). You promised in Field.h that such a constructor exists somewhere (which is why the compiler never complains), but you never define it. When the linker then tries to link the functions you declared with the functions that the compiler emitted, it notices that this constructor is missing and complains.
This is what the error messages are trying to tell you:
undefined reference to 'Sep::Field::Field()' -> The Field::Field() constructor is not defined anywhere.
In function Sep::Building::Building(...) -> It is trying to call the Field constructor in the shown Building constructor.
The simplest fix is to write Field() = default; so the compiler automatically generates the default constructor.
Edit: If you want to use the Field::Field(FieldType) constructor, this is how you would do that:
Building::Building(FieldType fieldType, /* etc */)
: Field(fieldType)
{
// etc.
}
You could also add a constructor to the Field class that takes all these arguments that you are trying to pass:
Field::Field(FieldType fieldType, std::string name, char abbrevation, /* etc. */)
: type_(fieldType), name_(name), abbrevation_(abbreviation), /* etc. */
{
}
And thus:
Building::Building(FieldType type, const std::string name, const char abbrevation, /* etc. */)
: Field(type, name, abbreviation, /* etc. */)
{
}
Even better, you can just "reuse" the long Field constructor for Building
class Building : public Field
{
public:
using Field::Field;
// ...
}

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;
};

"Use of undeclared identifier A"

Any ideas on what is causing this compile-time error?
Basic setup:
main.cpp
#include <iostream>
#include "GroupTheorizer.h"
int main()
{
// ...
functs::Adder<char> A; // error on this line
/ ...
return 0;
}
GroupTheorizer.h
#ifndef __GroupTheory__GroupTheorizer__
#define __GroupTheory__GroupTheorizer__
class GroupTheorizer
{
// definitions of members of a GroupTheorizer object
// ...
};
#endif /* defined(__GroupTheory__GroupTheorizer__) */
GroupTheorizer.cpp
#include "GroupTheorizer.h"
#include <set>
#include <iostream>
#include <limits>
#include <string>
// ... implementations of GroupTheorizer members
// ...
namespace functs
{
class Adder
{
private:
static const char symbol = '+';
public:
T operator() (const T & x, const T & y) const { return x + y; };
char getSymbol(void) const { return symbol; };
};
// other functors ...
// ...
}
I'm fairly certain I linked the files together correctly, so what could be the problem?
Looking at your implementation of Adder, it seems like you mean it to be a template but haven't written it as such.
You're only missing the template <typename T> line.
template <typename T>
class Adder
{
private:
static const char symbol = '+';
public:
T operator() (const T & x, const T & y) const { return x + y; };
char getSymbol(void) const { return symbol; };
};

How can assign a class value to another nested classes in 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.)