2

I am a newbie so please forgive me if this is really stupid.

Recently I made a project using qt in ubuntu and I used "QMAKE_CXXFLAGS += -std=c++11" for static linking,everything went well so I thought why not recompile it on windows,and I did.

This is node.h

#ifndef NODE_H
#define NODE_H
#include <iostream>
#include <string>
#include "qcustomplot.h"
using namespace std;
class node
{
public:
double p[6];
string table[3000][9];

double splitPoints[8];
double giniA[8];//array of ginies obtained by partitioning on corresponding attributes
double gini;//gini of a dataset
int rowc=0;//row count
int colc=0;
int cc;
std::string label;
string a[9];
node* left=NULL;
node* right=NULL;
void plotGraph(QCustomPlot *customPlot);
int optimize(int);


};

#endif // NODE_H

when I run my project I get the following error messages:

   In file included from ..\mining app final(hopefully)\/mythread.h:4,
             from ..\mining app final(hopefully)\/mainwindow.h:8,
             from ..\mining app final(hopefully)\main.cpp:2:
   ..\mining app final(hopefully)\/node.h:16: error: ISO C++ forbids initialization of  member 'rowc'
   ..\mining app final(hopefully)\/node.h:16: error: making 'rowc' static
   ..\mining app final(hopefully)\/node.h:16: error: ISO C++ forbids in-class   initialization of non-const static member 'rowc'
   ..\mining app final(hopefully)\/node.h:17: error: ISO C++ forbids initialization of member 'colc'
   ..\mining app final(hopefully)\/node.h:17: error: making 'colc' static
   ..\mining app final(hopefully)\/node.h:17: error: ISO C++ forbids in-class initialization of non-const static member 'colc'
   ..\mining app final(hopefully)\/node.h:21: error: ISO C++ forbids initialization of member 'left'
   ..\mining app final(hopefully)\/node.h:21: error: making 'left' static
   ..\mining app final(hopefully)\/node.h:21: error: invalid in-class initialization of static data member of non-integral type 'node*'
   ..\mining app final(hopefully)\/node.h:22: error: ISO C++ forbids initialization of   member 'right'
   ..\mining app final(hopefully)\/node.h:22: error: making 'right' static
   ..\mining app final(hopefully)\/node.h:22: error: invalid in-class initialization of         static data member of non-integral type 'node*'
   mingw32-make[1]: Leaving directory `C:/build-blah-vai-Debug'
   mingw32-make[1]: *** [debug/main.o] Error 1
   mingw32-make: *** [debug] Error 2
   01:36:17: The process "C:\MinGw\bin\mingw32-make.exe" exited with code 2.
   Error while building/deploying project blah (kit: vai)
   When executing step 'Make'
   01:36:17: Elapsed time: 00:02.

can anyone please guide me how to resolve this ?

I'm currently working on Qt 4.8.5-mingw (Windows 7)

  • You should initialize your member variables in the constructor. Only static variables can be initialized outside the class. – Vaibhav Desai Jul 03 '13 at 21:02
  • @VaibhavDesai That's [not true in C++11](http://www.stroustrup.com/C++11FAQ.html#member-init). Are you sure the right flags are getting passed to the compiler? – peppe Jul 03 '13 at 21:17
  • @VaibhavDesai I did as u suggested,and now it says "stod not a member of std". – Vaibhav Walia Jul 03 '13 at 21:17
  • @peppe QMAKE_CXXFLAGS += -std=c++11 dosen't work – Vaibhav Walia Jul 03 '13 at 21:19
  • Which GCC version is the one you're using with MinGW? Maybe it's just too old. You need GCC >= 4.7. – peppe Jul 03 '13 at 21:21
  • @peppe I downloaded "Qt libraries 4.8.5 for Windows (minGW 4.4, 317 MB)" AND MINgW 4.4,that too old ? – Vaibhav Walia Jul 03 '13 at 21:24
  • @peppe also can i use mingw>4.4 for this version ? – Vaibhav Walia Jul 03 '13 at 21:26
  • @user2548168 Yes, mingw 4.4 is too old, and don't support many C++11 features. It's unlikely you can use a recent mingw with that download, so you probably have to build Qt 4.8 yourself with a recent mingw, or use Qt 5.1 from http://qt-project.org/downloads – nos Jul 03 '13 at 21:42

2 Answers2

0

For my qt project on Windows I have used "QMAKE_CXXFLAGS += -std=c++0x" for new-standard features. MinGW 4.8 (supports many c++11 features) you may download here.

0

Well in order to avoid using any c++11 features I wrote my own "to_string()" and "to_Double()" functions and used them, Now It works like a charm !

Here are the functions:

string toString(double)

string toString(double num)
{
std::stringstream ss;

ss << num;
std::string s(ss.str());

return s;
}

double toDouble(string)

 double toDouble(string s)
 {
  int i,j;
  double p=0;

  for(i=s.size()-1;(s[i]!='.')&&(i>=0);i--)
  {
    p+=1.0;
  }

  if(s[i]!='.')
  p=0;

  else
  {
  for(j=i;j<s.size();j++)
  s[j]=s[j+1];
  }
  istringstream myStream(s);
  unsigned int uintVar = 0;

  myStream >> uintVar;

  return (uintVar/(double)(pow(10.0,p)));
 }