C++ 错误:')' 标记之前的预期主表达式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17771456/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 21:26:11  来源:igfitidea点击:

error: expected primary-expression before ‘)’ token

c++

提问by user2590797

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::KeyKor NewKeyPair1.

此代码的主要目的是在嵌套类NslObject::KeyKNewKeyPair1.

.cpp file

.cpp 文件

        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:

.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_;
   // 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 :

所以,cpp文件中这一行的问题:

 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

采纳答案by Mario

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:

解决 typedef 您基本上编写了以下内容:

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 typedefanyway? Did you try to name that NewKeyPair1? Something like this:

但是,我猜您typedef无论如何都误用了?你有没有尝试命名NewKeyPair1?像这样的东西:

NslObject::KeyK NewKeyPair1(RSA::GenerateKeyPair(keyLength));