3

How to fix this warning? The code cannot continue compile because of this warning. Please please give me some suggestions! Thank you so much! I copied four parts of the code where the warning points to.

 template <typename T>
std::vector<StructNodeElem<T> *> *_groupStructOfString(const char *data) throw(const char *){
  std::istringstream is(data);
  std::vector<StructNodeElem<T> *> *gstruct = new std::vector<StructNodeElem<T> *>;


template <typename T>
std::vector<StructNodeElem<T> *> *_readGroupStruct(const char *file) throw(const char *){
  std::ifstream infile;
  infile.open (file, ifstream::in);
  if(! infile.good())
    throw("readGroupStruct: cannot open file");


template <typename T>
std::vector<StructNodeElem<T> *> *_simpleGroupTree(int *degr, int n) throw(const char *){
  std::vector<int> degrees;
  for(int i = 0;i < n;i++)
    degrees.push_back(degr[i]);




template <typename T>
Vector<T> *_graphOfGroupStruct(std::vector<StructNodeElem<T> *> *gstruct,SpMatrix<bool> **pgroups,SpMatrix<bool> **pgroups_var) throw(const char *) {
  int nb_vars;
  Vector<T> *peta_g;
  if (! checkGroupTree<T>(gstruct,false,&nb_vars))
    throw("graphOfGroupStruct: bad input data");




template <typename T>
int _treeOfGroupStruct(std::vector<StructNodeElem<T> *> *gstruct,int **pperm,int *pnb_vars,Vector<T> **peta_g,SpMatrix<bool> **pgroups,Vector<int> **pown_variables,Vector<int> **pN_own_variables) throw(const char *){
  int nb_vars;
  *pnb_vars = 0;
  if (! checkGroupTree<T>(gstruct,true,&nb_vars))
    throw("treeOfGroupStruct: bad input data");
user3618186
  • 123
  • 1
  • 5
  • Use `noexcept` to instead indicate that a function does not throw, but I can't remember which version of MSVC, if any, supports that. – chris Jun 11 '14 at 18:37
  • Just do not use exception specifications besides throw() or noexcept (C++11) - please search the web for reasons –  Jun 11 '14 at 18:38
  • Also: Please throw an exception derived from std::exception, unless it's a really bad one (like std::bad_alloc). –  Jun 11 '14 at 18:43
  • @chris These functions are actually throwing, how would noexept help? – imreal Jun 11 '14 at 18:44
  • @imreal, It wouldn't here, but `noexcept` is better than `throw()` in general, and the general advice is not to have `throw(something)` at all. This is similar to `noexcept(false)`, which it would have by default. – chris Jun 11 '14 at 18:50
  • @chris agree on that. – imreal Jun 11 '14 at 18:51

1 Answers1

2

Check the msdn http://msdn.microsoft.com/en-us/library/sa28fef8.aspx.

Summary, just use the pragma #pragma warning( disable : 4290 )

imreal
  • 10,178
  • 2
  • 32
  • 48
  • Are you sure this is better advice considering the OP doesn't know why it happens/what it wants in order to not give the warning? – chris Jun 11 '14 at 18:39
  • 1
    @chris The problem is in the function declarations, Visual C++ just ignores the specification. It seems like the OP didn't write the code (and it might be working code except for the warnings) so it is better to just leave the specifications there. – imreal Jun 11 '14 at 18:43