简体   繁体   English

从main调用函数时出错

[英]error calling a function from main

I am trying to call two functions from one main function the code of my main func is as follows: 我试图从一个main函数调用两个函数,我的main函数的代码如下:

#include <watchdoggen.h>
#include <concat.h>
using namespace std;


int main () {
    string plain;
    char key1[16];
    char si[10];
    char w[10];
    char fid[20];

    cout << "Enter the number of splits: ";
    cin >> si;
    cout << "Enter the number of watchdogs: ";
    cin >> w;
    cout << "Enter the Fid: ";
    cin >> fid;
    concat(si, w, fid);
    //cout<<"\nThe plain txt is: "<< si <<endl;
    plain = si;
    cout << "the plaintext is: ";
    cin.ignore();
    getline(cin, plain);
    cout << "Enter the Master Key: ";
    cin>>key1;
    byte* key_s = (byte*)key1;
    cout << "key: " << plain << endl;
    watchdoggen(plain,key_s);
}

Here I am trying to basically give the output of one function as the input of the other function. 在这里,我试图基本上将一个函数的输出作为另一个函数的输入。 When I compile the code, I get the following error: 当我编译代码时,我收到以下错误:

test4watchdoggen.cpp: In function ‘int main()’:
test4watchdoggen.cpp:67:19: error: ‘concat’ was not declared in this scope

I am using the following command to compile : 我使用以下命令编译:

g++ -g3 -ggdb -O0 -DDEBUG -I/usr/include/cryptopp test4watchdoggen.cpp \
    watchdoggen.cpp concat.cpp -o test4watchdog -lcryptopp -lpthread

Need some help on this. 需要一些帮助。

concat.h concat.h

#ifndef TRY_H_INCLUDED
#define TRY_H_INCLUDED

char concat(char si[],char w[],char fid[]);

#endif

The include guard is used to prevent including the same header twice: include guard用于防止包含相同的头两次:

#ifndef MY_GUARD
#define MY_GUARD
// code ...
#endif

But this only works correctly if each header has a unique name for the guard. 但是这只有在每个标头都有一个唯一的防护名称时才能正常工作。 In your case, the guards in both of your headers have the same name TRY_H_INCLUDED , so including one automatically prevents the other from being included. 在您的情况下,两个标头中的警卫都具有相同的名称TRY_H_INCLUDED ,因此包括一个会自动阻止另一个包含。

The fix is to simply give each header file a unique name for the include guard as Hari Mahadevan suggested. 修复是简单地为每个头文件提供一个包含守卫的唯一名称,正如Hari Mahadevan建议的那样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM