tags:

views:

222

answers:

3

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.]

+11  A: 

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/... .

xtofl
That or "using std::vector;"
Rob K
+3  A: 

Your first problem is not declaring the namespace for the std lib:

using namespace std;
jsight
I prefer to just go ahead and use std:: on the front of everything, but he didn't do that either.
T.E.D.
Adding 'using namespace X' is a bit of a crutch for beginners. Polluting the namespace by bringing the while std namespace into global scope is at best overkill and at worst just lazy. Prefix vector with std:: or if you must 'using std::vector'
Martin York
@Martin: I agree... but he sounds like a beginner. :) Its a good thing to point out, though.
jsight
+2  A: 
seg.server.fault
It's not a good idea to have a using directive (using namespace std;) in a header file. Also, if you only want to access a single member of `std` then the using directive is probably overkill. However, in this case the code uses strings, vector and the stream operators. I think the single using directive is far more sensible than 5+ using declarations.
Richard Corden