string ok as public causes core dump as public

J

Jake

I have the following class definition

#include <string>
#include "embl.h"
using namespace std;
class Gene{
public:
Gene(EMBL::EmblSaap *cdsinfo,int snp_pos);
private:
string codonseq;
string protein_seq;
string status;
string message;
int readingframe;
// which codon in the protein seq
int codonpos;
// which allele within the codon is the snp based
int allelepos;
string nuc_seq;
};

Within the constructor after filling up the other variables I come
too:-

ahold2=nuc_seq.substr((newsnp_pos-allelepos),3);
cout<<"codon:"<<ahold2<<"\n";
codonseq=ahold2;

newsnp_pos and allelepos are sensible.
When I redefine the class with codonseq as public the code does not
dump core.
I think this problem has something to do with memory allocation, should
I initiliase the strings in someway to prevent this from happening?
regards jake
 
M

mlimber

Jake said:
I have the following class definition

#include <string>
#include "embl.h"
using namespace std;
class Gene{
public:
Gene(EMBL::EmblSaap *cdsinfo,int snp_pos);
private:
string codonseq;
string protein_seq;
string status;
string message;
int readingframe;
// which codon in the protein seq
int codonpos;
// which allele within the codon is the snp based
int allelepos;
string nuc_seq;
};

Within the constructor after filling up the other variables I come
too:-

ahold2=nuc_seq.substr((newsnp_pos-allelepos),3);
cout<<"codon:"<<ahold2<<"\n";
codonseq=ahold2;

newsnp_pos and allelepos are sensible.
When I redefine the class with codonseq as public the code does not
dump core.
I think this problem has something to do with memory allocation, should
I initiliase the strings in someway to prevent this from happening?
regards jake

Changing the access specifier (private to public) should have no effect
on the code generated by the compiler since that is a compile-time
construct only. So I'm guessing the problem is elsewhere. Please post
more of your code (preferably a minimal compilable sample that
demonstrates the problem; see
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.8).

Cheers! --M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top