Problem with MSVC++

This is a discussion on Problem with MSVC++ within the C++ Programming forums, part of the General Programming Boards category; Everytime I try to compile this: Code: class RecipeList { public: RecipeList(char[],char[],char[]); ~RecipeList(); void AddRecipe(char[],char[],char[]); void DeleteRecipe(RecipeStruct *); void SaveRecipe(RecipeStruct ...

  1. #1
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552

    Problem with MSVC++

    Everytime I try to compile this:

    Code:
    class RecipeList
    {
    public:
    	RecipeList(char[],char[],char[]);
    	~RecipeList();
    
    	void AddRecipe(char[],char[],char[]);
    	void DeleteRecipe(RecipeStruct *);
    	void SaveRecipe(RecipeStruct *);
    	void SaveToDisk();
    	RecipeStruct* GetPrevHandle(RecipeStruct*);
    	RecipeStruct* SearchIndex(const int);
    private:
    	RecipeStruct *Head, *Tail, *Current;
    };
    I get this:
    Code:
    --------------------Configuration: Recipe Manager - Win32 Debug--------------------
    Linking...
    main.obj : error LNK2001: unresolved external symbol "public: __thiscall RecipeList::RecipeList(char *,char *,char *)" (??0RecipeList@@QAE@PAD00@Z)
    Debug/Recipe Manager.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.
    
    Recipe Manager.exe - 2 error(s), 0 warning(s)
    The problem occurs with the constructor.

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    272
    What does your RecipeList constructor implementation look like?
    Joe

  3. #3
    Funniest man in this seat minesweeper's Avatar
    Join Date
    Mar 2002
    Posts
    801
    Code:
    RecipeList(char[],char[],char[]);
    You haven't given any variable names in the argument list. And I can't quite remember but I don't think you do char[] to pass an array into a function. You pass in a pointer to the first element If I remember correctly.

    I am sketchy on all this so If I am wrong, then sorry

  4. #4
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    you don't need to write the name for the argument when you are declaring.

    Here is the implementation:
    Code:
    RecipeList::RecipeList(char szRecName[], char szRecIngred[], char szRecInstr[])
    {
    	Head = new RecipeStruct;
    
    	Head->Next = NULL;
       Head->szRecipeIngredient = (char*)GlobalAlloc(GPTR, strlen(szRecIngred));
    	Head->szRecipeName = (char*)GlobalAlloc(GPTR, strlen(szRecName));
    	Head->szRecipeInstruction = (char*)GlobalAlloc(GPTR, strlen(szRecInstr));
    
    	Tail->szRecipeIngredient = szRecIngred;
    	Tail->szRecipeInstruction = szRecInstr;
    	Tail->szRecipeName = szRecName;
    
    	Tail = Head;
    	Current = Head;
    }

  5. #5
    Funniest man in this seat minesweeper's Avatar
    Join Date
    Mar 2002
    Posts
    801
    >>you don't need to write the name for the argument when you are declaring.<<

    Right you are, thanks. I learn something new every day when i come here.

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    I plugged your code into an empty project and it worked fine. Maybe in your Recipe implementation you didn't include the recipe.h file ?

  7. #7
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    I did include it, I just double checked

  8. #8
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    It should work fine. Post your code. The only possibility I can think of is that you have the implementation in a separate project than your call.

  9. #9
    Funniest man in this seat minesweeper's Avatar
    Join Date
    Mar 2002
    Posts
    801
    Just to clear something up, I have always been taught to declare a function like

    Code:
    function(int a, int b, int c);
    Can I actually declare it

    Code:
    function(int, int, int);
    thanks in advance

  10. #10
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Originally posted by minesweeper
    Just to clear something up, I have always been taught to declare a function like

    Code:
    function(int a, int b, int c);
    Can I actually declare it

    Code:
    function(int, int, int);
    thanks in advance
    yes, but when you define it you have to give them names.

  11. #11
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    I found out the problem. One of my intermediate files weren't updated the last time I compiled. I ran a clean and then rebuilt it and now it runs fine. Now I just got problems with my dynamic memory I got to work out.

  12. #12
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    what should I declare my char's as? I ran a debug and here is the line that is crashing the program:
    Code:
    Tail->szRecipeIngredient = szRecIngred;
    Apparently I can't set the dynamically created char to a char[]. What type of char's should I use for the parameters?

  13. #13
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Originally posted by frenchfry164
    what should I declare my char's as? I ran a debug and here is the line that is crashing the program:
    Code:
    Tail->szRecipeIngredient = szRecIngred;
    Apparently I can't set the dynamically created char to a char[]. What type of char's should I use for the parameters?
    No, it's because you tried to write to the data that Tail points to before you initialized it to a proper memory location. Set it to head before you write anything.

  14. #14
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    I can't believe I did that. I guess when you don't think and just throw crap in that careless mistakes like this happen .

  15. #15
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    Now I'm getting access errors with this:

    Code:
       while (Cur->Next != NULL && Cur->Next != TargetNode)
       {
          Cur = Cur->Next;
       }
    on the first line

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MSVC 2005 problem
    By l2u in forum Windows Programming
    Replies: 1
    Last Post: 05-13-2006, 05:30 PM
  2. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM
  3. Replies: 5
    Last Post: 11-07-2005, 10:34 PM
  4. MSVC Tutorial problem - Monochrome Palette
    By colinH in forum C++ Programming
    Replies: 4
    Last Post: 10-30-2002, 02:57 AM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM

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