What can go wrong?

This is a discussion on What can go wrong? within the C++ Programming forums, part of the General Programming Boards category; I have an assignment from a vector to another, that is: Code: ptrlin.assign( A.ptrlin.begin(), A.ptrlin.end() ) It gives a seg ...

  1. #1
    Registered User nepper271's Avatar
    Join Date
    Jan 2008
    Location
    Brazil
    Posts
    50

    What can go wrong?

    I have an assignment from a vector to another, that is:

    Code:
    ptrlin.assign( A.ptrlin.begin(), A.ptrlin.end() )
    It gives a seg fault.
    Code:
    Program received signal SIGSEGV, Segmentation fault.
    0x003b0003 in memmove () from /lib/tls/libc.so.6
    A.ptrlin is well defined, and I'm not trying to copy from ptrlin.

    It started when...

    Code:
    MATRIX *G;
    ...
    READ (..., *G, ...);
    and the definition:

    Code:
    READ (string src, MATRIX & G, ...)
    {
      ifstream file;
      int n, m;
    
      file.open (src.c_str());
      if (!file)
        {
          cout << "Error\n";
          return 0;
        }
      file >> n >> m;
    
    //---
      G = ZEROS <MATRIX> (n,n);
    }
    which calls...

    Code:
    void MATRIX::operator= (MATRIX const &A)
    {
      if (this == &A)
        return;
      n_lin = A.n_lin;
      n_col = A.n_col;
      numel = A.numel;
      val.assign(A.val.begin(), A.val.end());
      colind.assign(A.colind.begin(), A.colind.end());
      ptrlin.assign(A.ptrlin.begin(), A.ptrlin.end());
    }
    Can anybody help me?

    Thank you,
    Nepper271

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    G isn't pointing to anything, is it?

    Maybe you need to do
    Code:
    MATRIX *G = new MATRIX;
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User nepper271's Avatar
    Join Date
    Jan 2008
    Location
    Brazil
    Posts
    50
    Yes indeed, as MATRIX *G was a member of a class, I forgot to initialize it after a clear call, so there it is. Sorry for bringing silly problems, and thank you very much for your help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 04:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 01:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 02:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21