Hi there,

I am a Delphi guy and I am a bit new to C++. I have this annoying error when I try to compile and I have no idea how to solve this:
error: request for member ‘GetVector’ in ‘gff’, which is of non-class type ‘TGff_File*’ on line #20 .

My guess is that it has to do something with pointers but I am lost...

Could you please tell me what is wrong here ?

Thank you for your help,

Pasta


MyProg.cpp

#include "GFF_parse.h"

#include <iostream>
#include <fstream>
#include <sstream>
#include <string.h>
#include <time.h>



using namespace std;

void ReadVector(vector<TGff_Feature> AVect);


main(){
  
   TGff_File* gff = new TGff_File();
   
   ReadVector( gff.GetVector() ); //error here !
  
  
}

GFF_parse.h

#ifndef GFF_PARSE_H_INCLUDED
#define GFF_PARSE_H_INCLUDED

#include <iostream>
#include <fstream>
#include <sstream>
#include <string.h>
#include <vector>


class TGff_Feature;
class TGff_File;



class TGff_File
{

    public:
        TGff_File(std::string FileName);
        virtual ~TGff_File();
	const std::vector<TGff_Feature> GetVector() { return fFeatureVect };

    protected:

    private:
        std::string fFileName;
        std::vector<TGff_Feature> fFeatureVect;
        int ParseGFF();

};


class TGff_Feature
{
    public:
        TGff_Feature(std::string _Seqname, std::string _FeatType, int _Start, int _End, char _Strand );
        virtual ~TGff_Feature();

    protected:

    private:
        std::string fSeqname;        
        std::string fFeatureType;
        int fStart;
        int fEnd;        
        char fStrand;
};

GFF_parse.cpp

#include "GFF_parse.h"

#include <typeinfo>
#include <math.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <exception>
#include <string.h>
#include <stdlib.h>

using namespace std;




TGff_File::TGff_File(std::string FileName)//cons
{
    fFileName = FileName;
    ParseGFF();

}


TGff_File::~TGff_File(){ //dest

}



int TGff_File::ParseGFF(){

    /* Initialize vector here and fill it */
    
    return 1;
}




TGff_Feature::TGff_Feature(string _Seqname, string _FeatType, int _Start, int _End, char _Strand ) {
    fSeqname = _Seqname;
    fFeatureType = _FeatType;
    fStart = _Start;
    fEnd = _End;
    fStrand = _Strand;


}

TGff_Feature::~TGff_Feature(){


}

Dani AI

Generated

Nice find, — your fix is exactly right: the error came from using the member-access operator for an object (.) on a pointer. When a variable has type TGff_File* you must use -> to call its members; . is for actual objects (non-pointers).

A few follow-up suggestions to make the code safer and clearer:

  • Avoid copying the whole vector on each call. Make the reader take a const reference and make the accessor a const reference and const method:

    void ReadVector(const std::vector<TGff_Feature>& AVect);
    
    const std::vector<TGff_Feature>& GetVector() const { return fFeatureVect; }

    Returning a reference avoids a potentially expensive copy; marking the accessor const documents that it does not modify the object. Note: a reference is only safe while the TGff_File instance still exists.

  • Prefer RAII / smart pointers or stack allocation instead of naked new to avoid leaks and clarify ownership:

    TGff_File gff("file.gff");                 // stack, use '.' to access
    auto gffPtr = std::make_unique<TGff_File>("file.gff");  // pointer, use '->'
  • Other small cleanups: include <string> (not <string.h>) when using std::string, declare int main() and return 0;, and consider using emplace_back when filling the feature vector for efficiency.

Summary: the compile error was simply pointer vs object syntax; your -> fix is correct. For production code, also change signatures to use const references, avoid raw new, and confirm the accessor is const so callers cannot inadvertently modify internals or pay for unnecessary copies.

SOLVED !

Figured it out myself LOL
The solution is ReadVector( gff->GetVector() );
Note the use of -> cos' it is a pointer Dooooooh !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.