Reputation:
I need help with a c++ syntax issue I'm having.
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <fstream>
#include <stdlib.h>
#define RANGE 15.0
#define NUMBINS 15
struct _freq
{
float ini, end;
int q;
};
typedef _freq freq;
vector<freq> alphaCutoffSelector(vector<atom> A,string _i,string _j,float r=RANGE,
int b=NUMBINS);
vector<freq> alphaCutoffSelector(vector<atom> A,string _i,string _j,float range,
int bins)
{
vector<freq> F;
freq *f;
double D;
for (int i=0;i<bins;i++)
{
f=new freq;
f->ini=i*(range/bins);
f->end=f->ini+range/bins;
f->q=0;
F.push_back(*f);
}
for(int i=0;i<A.size();i++)
{
for (int j=0;j<A.size();j++)
{
for(int k=0;k<bins;k++)
{
if(i!=j && A[i].getResName()==_i &&
A[j].getResName()==_j && A[i].getAtomName()=="CA" &&
A[j].getAtomName()=="CA")
{
D = (A[j].getX()-A[i].getX())*(A[j].getX()-A[i].getX()) + (A[j].getY()-A[i].getY())*(A[j].getY()-A[i].getY()) + (A[j].getZ()-A[i].getZ())*(A[j].getZ()-A[i].getZ());
if (D > (k*range/bins)*(k*range/bins) && D <= ((k+1)*range/bins)*((k+1)*range/bins))
{
F[k].q=F[k].q+1;
}
}
}
}
}
return F;
}
vector<freq> C;
string RN[] = {"ALA","ARG","ASN","ASP","CYS","GLU","GLN","GLY","HIS","ILE","LEU","LYS","MET","PHE","PRO","SER","THR","TRP","TYR","VAL"};
int i,j;
for (i=0;i<20;i++)
{
for (j=0;j<20;j++)
{
if (i<=j)
{
C=alphaCutoffSelector(atoms,RN[i],RN[j]);
cout <<RN[i] <<"-" <<RN[j];
for (int n=0;n<NUMBINS;n++)
{
cout <<" " <<C[n].q;
}
cout << endl;
C.clear();
}
}
}
return 0;
}
Attempts to compile this using g++ -c try.cc result in the following error messages:
try.cc:1: error: expected constructor, destructor, or type conversion before '<' token.
what should i do??
[I tried - Ed.]
Upvotes: 0
Views: 359
Reputation: 20008
I guess you are having problem with not including std namespace
.
You can add using namespace std
in it, but
using namespace std
in header file is not good idea, instead you can do
and add others as per your need.
using std::cout;
using std::cin;
using std::endl;
using std::vector;
Sidenote,
consts are always preferred than define in C++.
so const float RANGE = 15.0
is always better than #define RANGE 15.0
.
For explanations and many more useful C++ tips, see Effective C++
Upvotes: 2
Reputation: 28409
Your first problem is not declaring the namespace for the std lib:
using namespace std;
Upvotes: 3
Reputation: 41509
I suspect you should write std::vector
. The compiler sees a symbol it doesn't understand (i.e. vector) and tries to treat it as a constructor/destructor/... .
Upvotes: 11