无法在开关盒内调用函数-C ++

时间:2019-09-25 15:12:04

标签: c++ function oop c++11 switch-statement

我正在尝试运行某种加密程序,但无法通过switch函数调用 void enc , 源代码:

#include <iostream>
#include <conio.h>
#include <windows.h>
#include <algorithm>
#include <string>

using namespace std;

int x,y,z,a,b,c,n;
char tabs[26][26],temp[512];
string input,output,Key;

void open();
void tableau();
void inchar();
void enc();
void dec();

int main() {
  open();
  cout << "1.\tEncrypt \n2.\tDecrypt \nOption: "; cin >> a;
  switch (a) {
    case 1:
      enc(); cout << a << "Debugger";
      break;
    case 2:
      dec();
    break;
  }
  return 0;
}

void enc(){
  void open();
  void inchar();
}

void dec(){

}

void inchar(){
  cout << "input: "; cin >> input; z = input.size();
  char dispos[input.size() + 1];
  copy(input.begin(),input.end(),dispos); dispos[input.size()] = '\0';
  for (int i = 0; i < z; i++) {
    temp[i] = dispos [i];
  }
}

void tableau() {
  cout << "Initialize Table Construct!!" << endl;
  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < 26; j++) {
      x = (i + j) % 26; y = x + 65;
      tabs[i][j] = y;
      cout << tabs[i][j] << " ";
    }
    cout << endl;
  }
}

void open() {
  cout << "Well Hello There";
}

每次选择选项1时,调试器提示就会不断出现。如果清除调试器,则代码结束。

P.S:我已经完成了将函数调用移到切换之前的操作,但是仍然没有任何作用。 P.S.S:对不起,英语不好。

1 个答案:

答案 0 :(得分:4)

问题是您的enc()函数 被调用了,但是它什么也没做!语法错误:

void enc(){
  void open();   // These lines DECLARE two NEW function ...
  void inchar(); // ... without ever calling them!
}

要调用这两个函数,请使用以下命令:

void enc(void) {
    open();
    inchar();
}
相关问题