error C2309: '{ctor}': is not a member of...

Discussion in 'C++' started by todd@weismannwebservices.com, Mar 18, 2007.

  1. Guest

    Here is the portion of my code giving a problem:

    #include <cassert>
    #include <iostream>
    using namespace std;

    template <class BaseData>
    class ListNode
    {
    BaseData listdata;
    ListNode *link;

    };

    template <class BaseData>
    class linklist {

    protected:
    ListNode<BaseData> *current, *head;

    public:
    //The class has the following required member functions:
    //1. Insert an item in numerical order
    void ordered_insert(const BaseData&);
    //2.Determine if the List is empty
    int listempty();
    //3.Search the list for an item and remove it
    void search_remove(BaseData);
    //4.Return the number of items in the list
    int listcount();
    //5. Insert an item at the beginning of the list.
    void insert_beg(BaseData);
    //6. Insert an item at the end of the list.
    void insert_end(BaseData);
    //7. Return and remove an item from the end of the list
    BaseData rt_end_value();
    //8. Return and remove an item from the beginning of the list
    BaseData rt_beg_value();
    //9. Return an Item from the list
    BaseData rt_value();
    //10. Moves pointer to the next item
    void move_next();
    //to print out the list for the driver program
    //overload stream insertion operator
    friend ostream & operator<<(ostream&, const linklist<BaseData>&);
    //These were done in class but I did not use
    int beg_list();
    int at_end();


    };


    template <class BaseData>
    linklist<BaseData>::linklist()
    {
    head = NULL;
    current = head;
    }//this is the line the problem is on but I would guess the input
    stream operator overloading is the problem

    template <class BaseData>
    ostream& operator<<(ostream& osObject, const linklist<BaseData>& list)
    {
    current = list.head;

    while(current != NULL)
    {
    osObject<<current-<info<<" ";
    current = current->link;
    }
    return osObject;
    }

    The problem is I am receiving an error: error C2309: '{ctor}': is not
    a member of 'linklist<BaseData>'

    I have included iostream so I know that is not the problem. I just
    can not figure it out. Any one have any ideas. I have marked the
    line the error comes up on.
     
    , Mar 18, 2007
    #1
    1. Advertising

  2. kwikius Guest

    On 18 Mar, 20:45, wrote:

    <...>

    > template <class BaseData>
    > class linklist {


    //#######################
    // add declaration of ctor in class definition ...
    linklist();
    //###############
    /*
    ....
    */
    };

    <...>


    > The problem is I am receiving an error: error C2309: '{ctor}': is not
    > a member of 'linklist<BaseData>'


    regrads
    Andy Little
     
    kwikius, Mar 18, 2007
    #2
    1. Advertising

  3. kwikius Guest

    On 18 Mar, 21:00, "kwikius" <> wrote:
    > On 18 Mar, 20:45, wrote:
    >
    > <...>
    >
    > > template <class BaseData>
    > > class linklist {

    >
    > //#######################
    > // add declaration of ctor in class definition ...


    // hmm... probably want it public too ..

    public:
    > linklist();
    > //###############
     
    kwikius, Mar 18, 2007
    #3
  4. Guest

    On Mar 18, 5:01 pm, "kwikius" <> wrote:
    > On 18 Mar, 21:00, "kwikius" <> wrote:
    >
    > > On 18 Mar, 20:45, wrote:

    >
    > > <...>

    >
    > > > template <class BaseData>
    > > > class linklist {

    >
    > > //#######################
    > > // add declaration of ctor in class definition ...

    >
    > // hmm... probably want it public too ..
    >
    > public:
    >
    > > linklist();
    > > //###############




    Thanks for the help...I did figure that out and felt a little stupid
    afterwards :) but now I am having a new error when linking. The
    overload of the insertion operator must be having a problem after
    all. My cout's in main for a linklist object are outputting errors
    when linking. The erros are:

    Error 1 error LNK2019: unresolved external symbol "class
    std::basic_ostream<char,struct std::char_traits<char> > & __cdecl
    operator<<(class std::basic_ostream<char,struct std::char_traits<char>
    > &,class linklist<int> const &)" (??6@YAAAV?$basic_ostream@DU?

    $char_traits@D@std@@@std@@AAV01@ABV?$linklist@H@@@Z) referenced in
    function _wmain assignment4.obj


    Error 2 fatal error LNK1120: 1 unresolved externals F:\CS
    255\assignment4\Debug\assignment4.exe 1
     
    , Mar 18, 2007
    #4
  5. Guest

    And I did fix:
    osObject<<current-<info<<" ";
    to:
    osObject<<current->info<<" ";

    Already
     
    , Mar 18, 2007
    #5
  6. Guest

    On Mar 18, 5:48 pm, wrote:
    > On Mar 18, 5:01 pm, "kwikius" <> wrote:
    >
    >
    >
    > > On 18 Mar, 21:00, "kwikius" <> wrote:

    >
    > > > On 18 Mar, 20:45, wrote:

    >
    > > > <...>

    >
    > > > > template <class BaseData>
    > > > > class linklist {

    >
    > > > //#######################
    > > > // add declaration of ctor in class definition ...

    >
    > > // hmm... probably want it public too ..

    >
    > > public:

    >
    > > > linklist();
    > > > //###############

    >
    > Thanks for the help...I did figure that out and felt a little stupid
    > afterwards :) but now I am having a new error when linking. The
    > overload of the insertion operator must be having a problem after
    > all. My cout's in main for a linklist object are outputting errors
    > when linking. The erros are:
    >
    > Error 1 error LNK2019: unresolved external symbol "class
    > std::basic_ostream<char,struct std::char_traits<char> > & __cdecl
    > operator<<(class std::basic_ostream<char,struct std::char_traits<char>> &,class linklist<int> const &)" (??6@YAAAV?$basic_ostream@DU?
    >
    > $char_traits@D@std@@@std@@AAV01@ABV?$linklist@H@@@Z) referenced in
    > function _wmain assignment4.obj
    >
    > Error 2 fatal error LNK1120: 1 unresolved externals F:\CS
    > 255\assignment4\Debug\assignment4.exe 1


    I changed the ostream declaration to:
    template <class BaseData> friend ostream & operator<<(ostream&, const
    linklist<BaseData>&);
    and that fixed it.
     
    , Mar 19, 2007
    #6
    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. Apricot
    Replies:
    4
    Views:
    556
    velthuijsen
    Apr 16, 2004
  2. NVH
    Replies:
    8
    Views:
    516
    mlimber
    Jul 6, 2006
  3. Grizlyk
    Replies:
    8
    Views:
    506
    Grizlyk
    Nov 29, 2006
  4. Replies:
    1
    Views:
    574
    David Harmon
    Mar 18, 2007
  5. , India

    copy ctor vs default ctor

    , India, Aug 15, 2007, in forum: C++
    Replies:
    2
    Views:
    427
    =?ISO-8859-1?Q?Erik_Wikstr=F6m?=
    Aug 15, 2007
Loading...

Share This Page