构造函数在C ++中遇到麻烦

时间:2013-12-04 14:51:40

标签: c++ c++11 constructor const

我在这里发现了很多类似的问题,但没有一个对我有帮助,所以在这里。我有以下3个文件;第一个是Includes.h:

#ifndef INCLUDES_H_
#define INCLUDES_H_

#include<fstream>
#include<sstream>
#include<algorithm>
#include<array>
#include<vector>
#include<chrono>
#include<iostream>
#include<random>
#include<iterator> 
#include<utility>
#include<functional>
#include<math.h>
#include<string>

using namespace std;

#endif /* INCLUDES_H_ */

第二个是Attack.h

#ifndef ATTACK_H_
#define ATTACK_H_

#include "Includes.h"

class Attack {

public:
  //constructor random attack/key of dimension, nrofkeys                                
  Attack(const int& d,const int& k);
  //constructor given attack/key                                                        
  Attack(const string& attckRes,const vector<int>& corKey);
  //deconstructor                                                                       
  virtual ~Attack();
  //data management                                                                     
  vector<int> getKey() const;
  double getpKey() const;
  vector<vector<double>> getPMF() const;
  vector<vector<int>> getkPMF() const;
  //print stuff                                                                         
  void printPMF();
  void printkPMF();
  void printpKey();
  void printKey();

 protected:
  double pKey;
  vector<int> key;
  vector<vector<double>> PMF;
  vector<vector<int>> kPMF;
};
#endif /* ATTACK_H_ */

最后是Attack.cpp类(我省略了一些功能):

#include "Attack.h"

//Constructor random attack                                                             
Attack::Attack(const int& d,const int& k) : pKey(1.0){
  random_device rd;
  mt19937 el(rd());
  uniform_real_distribution<> urd(0,1);
  double count = 0.0;
  vector<double> temp;
  vector<int> temp2;
 // more code
}
Attack::Attack(const string& attckRes,const vector<int>& corKey) : key(corKey),pKey(1.0    ) {
  string line;
  char str[50];
  ifstream data(attckRes);
  double val;
  int n;
  int sub;
  int count = 1;
  double count2=0.0;
  vector<double> temp;
 // more code
}

/* more code

然后我(在foo.cppp中)运行:

#include "Attack.h"

int main(){
   Attack myAt((int) 4,(int) 8);
   myAt.printPMF();
   myAt.printkPMF();
   myAt.printKey();
   myAt.printpKey();
   return 0;
}

我收到以下错误:

g++ -c Attack.cpp  -std=c++11
Attack.cpp:10:1: error: prototype for ‘Attack::Attack(const int&, const int&)’ does not match any in class ‘Attack’
 Attack::Attack(const int& d,const int& k) : pKey(1.0){
 ^
Attack.h:12:7: error: candidates are: Attack::Attack(const Attack&)
 class Attack {
       ^
Attack.h:18:3: error:                 Attack::Attack(const string&, const std::vector<int>&)
   Attack(const string& attckRes,const vector<int>& corKey);
   ^
Attack.h:16:3: error:                 Attack::Attack(int, int)
   Attack(const int& d,const int& k);
   ^
make: *** [Attack.o] Error 1

错误是在构造函数中的某个地方,但我无法弄清楚在哪里。有人可以帮助我吗?

0 个答案:

没有答案