-
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.
-
What does your RecipeList constructor implementation look like?
-
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 :D
-
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;
}
-
>>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.
-
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 ?
-
I did include it, I just double checked
-
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.
-
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
-
Quote:
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.
-
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.
-
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?
-
Quote:
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.
-
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:p .
-
Now I'm getting access errors with this:
Code:
while (Cur->Next != NULL && Cur->Next != TargetNode)
{
Cur = Cur->Next;
}
on the first line