Class Problems >.<

This is a discussion on Class Problems >.< within the C++ Programming forums, part of the General Programming Boards category; Well I'm getting a Linker error for the two functions in my class i created. Code: [Linker error] undefined reference ...

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    9

    Unhappy Class Problems >.<

    Well I'm getting a Linker error for the two functions in my class i created.
    Code:
     [Linker error] undefined reference to `Customer::GetLines(char*)'
      [Linker error] undefined reference to `Customer::GetData(int)' 
      ld returned 1 exit status
    I am not sure what it is yelling at me for, please give me an idea. =D

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by crateofrum
    Well I'm getting a Linker error for the two functions in my class i created.
    Code:
     [Linker error] undefined reference to `Customer::GetLines(char*)'
      [Linker error] undefined reference to `Customer::GetData(int)' 
      ld returned 1 exit status
    I am not sure what it is yelling at me for, please give me an idea. =D
    It sounds like you may have only declared these functions and failed to define them. Perhaps you could also post the offending code?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    9
    I will gladly post my code =D
    EDIT : Updated with Dave's Correction's (Thanks Dave =D )
    Code:
    #include <iostream>      /*        This is another way to make comments      */
    #include <iomanip>       /*    These are the headers we need, so remember to */
    #include <fstream>       /*  use them all wisely. Hopefully you will learn   */
    #include <sstream>       /*  past where i have gotten with these tutorials   */
    #include <string>        /*    You are our programming legacy, feel honoured.*/
    
    
    using namespace std; 
    using namespace std::ios;
    
    class Customer //Class for the C++ Tutorial Register
    {
       private:
       public:
    
              ostringstream File_ID;
              ofstream b_file();
              Customer();
              ~Customer(); 
              char Customer::GetData(int id2);
              int id2;
              int blah;
              char* file;
              char* memblock;
              int y;
              int Customer::GetLines(char *file);
                
    }search;
    
    Customer::Customer() //Constructor for the C++ Class
    {         
    };
    Customer::~Customer() //destructor for the C++ Class
    { 
    }; 
    
    int Customer::GetLines(char *file)
    {
            int y = 0;
            string line;
            
            ifstream productlist(file);
            if(productlist.is_open())
            while (! productlist.eof() )
                {
                  getline (productlist,line);
                  y++;
                }
                productlist.close();
    
            return y; //Returns the number of lines in the .txt file.
    }; 
     
    char Customer::GetData(int *id2) 
    { 
    ostringstream File_ID;
    
    File_ID<<id2 + ".txt";
    fstream b_file(File_ID.str().c_str(), in|ate);
    fstream::pos_type size;
    char * memblock;
      if (b_file.is_open())
      {
        size = b_file.tellg();
        memblock = new char [size];
        b_file.seekg (0, ios::beg);
        b_file.read (memblock, size);
        b_file.close();
        }
            return memblock[size];  //Returns the text from inside the File_ID.txt
      
    };
    So I just had a thought, do you also need to see the main code that uses this class maybe? By the way if u are wondering about the search;'s i didnt know where to declare an object of the class for certain cases. and sorry for being the noob who asks questions =\
    Last edited by crateofrum; 01-16-2007 at 11:34 PM.

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Oh, my.

    I don't believe this is correct,
    Code:
    using namespace ios;
    do you mean this?
    Code:
    using std::ios;
    My compiler complains here:
    Code:
    char GetData(id2);
    Do you mean this?
    Code:
    char GetData(int *id2);
    C++ is case sensitive.
    Code:
       int GetLines(char *file);
    //...
    int Customer::Getlines(char *file)
    What is with these?
    Code:
    }search;
    Sorry, there's still more, just listen to your compiler.
    [edit]Visit the FAQ.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Registered User
    Join Date
    Jan 2007
    Posts
    9
    thanks for the help, though its still giving me the same darn error msgs =\
    I've gone over to make sure im declaring the functions the right way, i wish the tutorial gave a little more complex class example.
    Thx for the help tho =D hopefully i can get it working by sunrise !

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM
  2. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 04:01 PM
  3. class Template problems
    By Mr_roboto in forum C++ Programming
    Replies: 8
    Last Post: 02-16-2006, 09:21 PM
  4. Replies: 3
    Last Post: 10-31-2005, 11:05 AM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 06:18 AM

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