string ok as public causes core dump as public

Discussion in 'C++' started by Jake, Nov 11, 2005.

  1. Jake

    Jake Guest

    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
     
    Jake, Nov 11, 2005
    #1
    1. Advertising

  2. Jake

    mlimber Guest

    Jake wrote:
    > 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
     
    mlimber, Nov 11, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. BlueDoze
    Replies:
    2
    Views:
    1,219
    Gordon Beaton
    May 4, 2004
  2. Replies:
    2
    Views:
    1,848
  3. halfdog
    Replies:
    12
    Views:
    12,585
  4. loudking

    free causes core-dump

    loudking, Jan 9, 2008, in forum: C Programming
    Replies:
    4
    Views:
    937
    Keith Thompson
    Jan 11, 2008
  5. Sheldon

    printf() causes core dump

    Sheldon, Feb 27, 2008, in forum: C Programming
    Replies:
    20
    Views:
    1,280
    Richard
    Mar 1, 2008
Loading...

Share This Page