简体   繁体   中英

Member variable in scope of one member function but not the other

I'm seriously confused why this is happening. I get an error 'enzyme_acronyms_ was not declared in this scope'. It points to my writeAcronym function but not getAcronym, and both use enzyme_acronyms_. What can possibly cause this?

SequenceMap.h

#ifndef SequenceMap_h
#define SequenceMap_h

#include <iostream>
#include <string>
#include <vector>

using namespace std;

class SequenceMap
{
    private:
        string recognition_sequence_;
        vector<string> enzyme_acronyms_;
    public:
        string getAcronym();
        void writeAcronym(string an_enz_acro);
}

SequenceMap.cpp

#include "SequenceMap.h"

string SequenceMap::getAcronym()
{
    return enzyme_acronyms_[0];        //works fine
}

void writeAcronym(string an_enz_acro)
{
    enzyme_acronyms_.push_back(an_enz_acro);     //enzyme_acronyms_ not declared in this scope
}

你错过了第二个函数定义的SequenceMap:: qualified:

void SequenceMap::writeAcronym(string an_enz_acro)

It must be declared like this:

void SequenceMap::writeAcronym(string an_enz_acro)
{
    enzyme_acronyms_.push_back(an_enz_acro);
}

You forgot the class scope SequenceMap:: .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM