簡體   English   中英

從main調用函數時出錯

[英]error calling a function from main

我試圖從一個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);
}

在這里,我試圖基本上將一個函數的輸出作為另一個函數的輸入。 當我編譯代碼時,我收到以下錯誤:

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

我使用以下命令編譯:

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

需要一些幫助。

concat.h

#ifndef TRY_H_INCLUDED
#define TRY_H_INCLUDED

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

#endif

include guard用於防止包含相同的頭兩次:

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

但是這只有在每個標頭都有一個唯一的防護名稱時才能正常工作。 在您的情況下,兩個標頭中的警衛都具有相同的名稱TRY_H_INCLUDED ,因此包括一個會自動阻止另一個包含。

修復是簡單地為每個頭文件提供一個包含守衛的唯一名稱,正如Hari Mahadevan建議的那樣。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM