Vector of My Datatype + Func

This is a discussion on Vector of My Datatype + Func within the C++ Programming forums, part of the General Programming Boards category; Code + Error : class Something{ private: vector <F_Letter> *all_letters; public: void show(); }; I need to be able to ...

  1. #1
    Something Clever ginoitalo's Avatar
    Join Date
    Dec 2001
    Posts
    187

    Vector of My Datatype + Func

    Code + Error :

    class Something{
    private:
    vector <F_Letter> *all_letters;
    public:
    void show();
    };

    I need to be able to say something like :

    all_letters[5].show();

    What I get :
    error C2039: 'show' : is not a member of 'vector<class F_Letter,class std::allocator<class F_Letter> >'

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    Code:
    class Something{
    private:
    vector <F_Letter> all_letters;
    public:
    void show();
    };
    The vector provides an [] operator, the pointer itself natively supports the [], so you would have needed to use two [] in order to have value semantics on the F_Letter if you used a vector <F_Letter>*, rather than a vector<F_Letter>
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    Something Clever ginoitalo's Avatar
    Join Date
    Dec 2001
    Posts
    187
    The Vector is used to store pointers of objects that are of my own datatype. So, how would I code the Vector to hold pointers to my datatype then call the show() function on lets say the 3rd pointer.

    Thanks a ton

  4. #4
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    Code:
    class Something{
    private:
    vector <F_Letter*> all_letters;
    public:
    void show();
    };
    
    Something aSomething;
    aSomething.all_letters[3]->show();  // easiest way, use -> operator
    *(aSomething.all_letters[3]).show(); // uglier way
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Datatype
    By ssharish2005 in forum C Programming
    Replies: 6
    Last Post: 08-04-2008, 12:53 PM
  2. warning LNK4049: locally defined symbol Func() imported
    By cpjust in forum C++ Programming
    Replies: 9
    Last Post: 01-17-2008, 05:19 PM
  3. how can i call a func by touching some adrs ?
    By jabka in forum C Programming
    Replies: 6
    Last Post: 04-25-2007, 01:41 PM
  4. typedef a func
    By trekker in forum C Programming
    Replies: 4
    Last Post: 07-02-2002, 05:15 AM
  5. Delete & print func()
    By spentdome in forum C Programming
    Replies: 5
    Last Post: 05-29-2002, 09:02 AM

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