Having trouble with this class...

This is a discussion on Having trouble with this class... within the C++ Programming forums, part of the General Programming Boards category; Hi, I am looking to use a vector to store objects of another class, however the borland compiler keeps telling ...

  1. #1
    Qui
    Qui is offline
    Registered User
    Join Date
    May 2003
    Posts
    30

    Having trouble with this class...

    Hi, I am looking to use a vector to store objects of another class, however the borland compiler keeps telling me type name expected and declaration missing.

    Code:
    #ifndef RecipeH
    #define RecipeH
    #include <vector>
    #include "Ingredients.h"
    
    //---------------------------------------------------------------------------
    class Recipe
    {
    private:
            AnsiString RecipeName;
            AnsiString RecipeDesciption;
            double Time;
            vector<Ingredients> IngredientsUsed;
    
    public:
            Recipe();
            ~Recipe();
           void setRecipe(AnsiString aRecipeName,AnsiString aRecipeDescription,
            double aTime);
    };
    is there anything wrong with this code?

    Also I am getting a whole load of errors with this code:

    Code:
    class Ingredients
    {
    protected:
            AnsiString IngredientName;
            AnsiString IngredientDescription;
            int Amount;
    
    public:
            Ingredients();
            ~Ingredients();
            void setIngredients(AnsiString aIngredientName,
            AnsiString aIngredientDrescription,int aAmount);
            AnsiString getIngredientName();
            AnsiString getIngredientDescription();
            int getAmount();
    };
    this is the errors i get:

    http://aamericandream.net/errors.GIF

  2. #2
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    It looks to me like you'll fix a whole load of errors by including the AnsiString header in the Ingredients file.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  3. #3
    Qui
    Qui is offline
    Registered User
    Join Date
    May 2003
    Posts
    30
    thanks, cured the ingredients classes numerous errors (didnt use to have to include the file in 5.02 of cbuilder now I do ...odd), any solution for the vector problems, dreading having to chose LL over vectors but it may turn out that way if this doesnt work.

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    if vector is of the Standard Template Library, rather than a proprietary Borland library, then you may need to indicate the namespace you are using to locate vector. Maybe something like:

    std::vector<Ingredients> IngredientsUsed;

    though that by itself shouldn't give a lot of error messages.

  5. #5
    Qui
    Qui is offline
    Registered User
    Join Date
    May 2003
    Posts
    30
    yup that fixed it lol i feel so stupid, these are such simple things. thanks for the help guys would of been sitting here all night trying to figure it out.

  6. #6
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>type name expected
    Well, since it's the same error as the AnsiString error, it looks to me like the problem is that it can't figure out what either Ingredients or vector is. Since we've included the Ingredients header, it knows what that is; and since we've included <vector>, it should know what vector is too. But wait a sec, vector is part of the std namespace.. Bingo, elad's got the answer You need to use std::vector, or else put a using namespace std; name before your class.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  7. #7
    Qui
    Qui is offline
    Registered User
    Join Date
    May 2003
    Posts
    30
    Yup, do you know why cbuilder 6 asks for the inclusion of the ansistring header but cbuilder 5.02 does not?

  8. #8
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Is the entire program exactly the same as when you compiled with 5.02, or did you just take sections from another program and plug it in? Because if you included the AnsiString header in a file, and included the Ingredients header right under it, then the AnsiString might not be needed to be included in the Ingredients header, since both of the header files just get plugged into the top of the file that included them, in the order that they get included - so logically, the AnsiString will be "included" in the Ingredients header in that case, though you don't do the including in the same file.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  9. #9
    Qui
    Qui is offline
    Registered User
    Join Date
    May 2003
    Posts
    30
    Yup your right it was included in the old version of the code that ran on 5.02 above the ingredients.h.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 09:10 AM
  2. Replies: 3
    Last Post: 10-31-2005, 12:05 PM
  3. Trouble with a class variable
    By TravisDane in forum C++ Programming
    Replies: 9
    Last Post: 12-08-2002, 12:59 AM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 02:30 PM

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