seg fault somewhere cannot find

This is a discussion on seg fault somewhere cannot find within the C++ Programming forums, part of the General Programming Boards category; i have Code: <<<FILE1.CPP>>> #include <string> #include "Customer.h" using namespace std; //in a functino somewhere Customer * person1; char name[50]; ...

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    91

    seg fault somewhere cannot find

    i have
    Code:
    <<<FILE1.CPP>>>
    #include <string>
    #include "Customer.h"
    using namespace std;
    
    //in a functino somewhere
    
    Customer * person1;
    char name[50];
    cin.getline(name, 50);
    person1->setName(name);
    
    
    <<CUSTOMER.CPP>>
    #include "Customer.h"
    
    void Customer::setName(string x) {
      Name = x;
    }
    -----------------
    this is giving me a seg fault, this code looks fine to me??
    and this is all i get from gdb
    Program received signal SIGSEGV, Segmentation fault.
    0x00216a43 in std::string::assign () from /usr/lib/libstdc++.so.5
    (gdb) where
    #0 0x00216a43 in std::string::assign () from /usr/lib/libstdc++.so.5
    #1 0x00215d26 in std::string:perator= () from /usr/lib/libstdc++.so.5
    #2 0x08049149 in Customer::setAdd ()
    #3 0x0804987a in FILE1::menu ()
    #4 0x08048cdb in main ()
    (gdb)

    i found that when i go to do
    cout << Name; (in setName functin)
    that gives me a segfault./. so do i need to initialise it to something?
    Last edited by paperbox005; 12-19-2004 at 10:15 PM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    > Customer * person1;
    This doesn't point anywhere

    > person1->setName(name);
    So this blows up.

    Try beginning with
    Customer * person1 = new Customer;

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    they really should explain this better in the tutorials...everyday it's the same question
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting a seg fault
    By ammochck21 in forum C Programming
    Replies: 11
    Last Post: 01-23-2009, 04:27 AM
  2. next_permutation seg fault
    By zxcv in forum C++ Programming
    Replies: 9
    Last Post: 12-14-2008, 06:40 AM
  3. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  4. Replies: 3
    Last Post: 10-15-2008, 09:24 AM
  5. Seg fault out of no where
    By mart_man00 in forum C Programming
    Replies: 5
    Last Post: 02-25-2003, 07:51 PM

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