c++ - Expected primary expression before -


i have following code in translator.h file

class dictionary {   public:   dictionary(const char dictfilename[]);   void translate(char out_s[], const char s[]);  

and call function in translator.cpp file follows

for (int i=0; i<2000;i++)  { dictionary:: translate (out_s[],temp_eng_words[i]);  } 

which gives me error "expected primary expression before ']' token". don't understand wrong, , decided against putting whole code if problem can found in above snippet.

any ideas??

i tried without [] out_s, gives me error "cannot call member function void dictionary::translate (char*, const char *) without object". i'll post whole code give clearer indication of problem might be.

translator.cpp  #include <iostream> #include <fstream> #include <sstream> #include <cstring> #include "translator.h"  using namespace std;  void dictionary::translate(char out_s[], const char s[]) { int i; char englishword[max_num_words][max_word_len];  (i=0;i < numentries; i++) { if (strcmp(englishword[i], s)==0) break; }  if (i<numentries) strcpy(out_s,elvishword[i]); }  char translator::toelvish(const char elvish_line[],const char english_line[])  { int j=0; int k=0; char temp_eng_words[2000][50]; char out_s; //char temp_elv_words[2000][50]; not sure if need  std::string str = english_line; std::  istringstream stm(str); string word; while( stm >> word) // read white-space delimited tokens 1 one {  strcpy (temp_eng_words[k],word.c_str());  k++;  }  (int i=0; i<2000;i++) { dictionary:: translate (out_s,temp_eng_words[i]); // error relates line -     cannot call member function this.    error -  expected primary expression // before ] if written out_s[].  } }    translator::translator(const char dictfilename[]) : dict(dictfilename) { char englishword[2000][50]; char temp_eng_word[50]; char temp_elv_word[50]; char elvishword[2000][50]; int num_entries;  fstream str;  str.open(dictfilename, ios::in); int i;  while (!str.fail()) { (i=0; i< 2000; i++) { str>> temp_eng_word; str>> temp_elv_word; strcpy(englishword[i],temp_eng_word); strcpy(elvishword[i],temp_elv_word);  }  num_entries = i;  }   str.close();  } } 

translator.h

const int max_num_words=2000; const int max_word_len=50;  class dictionary {  public: dictionary(const char dictfilename[]); void translate(char out_s[], const char s[]); // s represents wor out_s,    translated word  private:  char englishword[max_num_words][max_word_len]; char elvishword[max_num_words][max_word_len]; int numentries; };  class translator { public:  translator(const char s[]);  char toelvish(const char out_s[],const char s[]);  char toenglish(char out_s[], const char s[]);   private:   dictionary dict;  }; 

the problem passing out_s[], try one:

dictionary::translate (out_s,temp_eng_words[i]);  

if out_s array passing without [] enough.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -