Need some help with inheritence with STL

Discussion in 'C++' started by pb, Nov 18, 2004.

  1. pb

    pb Guest

    Im getting this compile error,
    undefined reference to BitString<10>::scramble()
    collect2: ld returned 1 exit status

    For some reason the compiler cant find the symbol for the member function i
    declare. Everythign compiles correctly up to the point when i make a call to
    the "scramble" routine. Calling the member functions of the base class work
    just fine, but when i try to call the member functions i declare in the
    extened class, the linker cant find the symbols. any ideas?

    thx for the help...

    // BitString.h

    #include <bitset>
    using namespace std;

    template <size_t N>
    class BitString : public bitset <N> {
    public:
    Bitstring <N>():bitset<N>(){};
    void scramble();
    };

    //Bitstring.cpp

    template <size_t N>
    BitString<N>::scramble()
    {
    return;
    }

    // main.cpp
    #include "BitString.h"
    int
    main()
    {
    BitString<10> data;
    data.scramble()
    return;
    }
     
    pb, Nov 18, 2004
    #1
    1. Advertising

  2. pb

    David Harmon Guest

    On Wed, 17 Nov 2004 21:44:08 -0800 in comp.lang.c++, "pb"
    <> wrote,
    >Im getting this compile error,
    >undefined reference to BitString<10>::scramble()


    This issue is covered in Marshall Cline's C++ FAQ. See the topics
    "[34.12] Why can't I separate the definition of my templates class
    from it's declaration and put it inside a .cpp file?" and
    "[34.13] How can I avoid linker errors with my template functions?".
    It is always good to check the FAQ before posting. You can get the
    FAQ at:
    http://www.parashift.com/c -faq-lite/
     
    David Harmon, Nov 18, 2004
    #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. Doug Nichols

    Inheritence question

    Doug Nichols, Feb 19, 2004, in forum: Perl
    Replies:
    0
    Views:
    459
    Doug Nichols
    Feb 19, 2004
  2. Guest
    Replies:
    0
    Views:
    701
    Guest
    Feb 25, 2004
  3. Mark
    Replies:
    1
    Views:
    651
  4. =?Utf-8?B?Q2hyaXM=?=

    Help Help. I really need some help with this

    =?Utf-8?B?Q2hyaXM=?=, Jan 31, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    588
    =?Utf-8?B?SmFzb24gVmVybWlsbGlvbg==?=
    Jan 31, 2007
  5. Domino
    Replies:
    5
    Views:
    405
    dorayme
    Nov 5, 2006
Loading...

Share This Page