EDIT:Has been fixed.
So, I'm using Dev-C++ 4.9.9.2 (if it's important) and whenever I compile my code, I get this error: C:\DOCUME~1\MATU~1\PRACOV~1\C__~1\bjsource\Makefile.win [Build Error] ["../../../../../Documents and Settings/Matuš/Pracovná plocha/C++/bjsource/card.o"] Error 1
This is the "main.cpp" code:
This is the "card.h" code:
And this is the "card.cpp" code:
#include <string> #include "card.h" Card::Card(int v, std::string path) { val=v; imgPath=path; if(v==11) ace=true; else ace=false; } int Card::getVal() {return val;} bool Card::isAce() {return ace;} std::string Card::getImgPath() {return imgPath;}
Anyone has an idea where the problem might be? I'd appreciate any useful answer.
Has card.o been built and exists in the relevant folder? Also there is no deconstructor in your class...
Oh, thanks. The problem was that I haven't built all my classes (only main.cpp) and that caused error.
PS: I think that destructor isn't that that important, or is it?
PS: I think that destructor isn't that that important, or is it?
General rule is that if you make your own constructor you need to make your own destructor.
That's not really true. Most classes have a constructor, but they don't necessarily need a destructor.
The general rule is that if the class acquires resources (not necessarily at the constructor(s)), it'll need a destructor to release them (unless it's done somewhere else). This is not the case of the OP.
Using devcpp by the way is like using void main in your programming... way out of date.
It gets the job done and is pretty simple for the most part.
I do recommend Code::Blocks over it though.
That's not really true. Most classes have a constructor, but they don't necessarily need a destructor.
That is not what they drilled into us in my advanced programming course. Kept telling us that if you make a custom constructor then you need to make a custom destructor. Also was told to never use the default constructor, but to write one that at least initializes everything to a default value.
Your advanced programming course instructor probably decided it's safer to teach "always include a constructor/destructor" and then let people learn about the exceptions afterwards, rather than the other way around.
As Oscar said, you typically only need a destructor if your class acquires some sort of resource (allocating memory, opening a file, etc.) that needs to be released when the class is destroyed.
For example: If you have a class that contains a pointer, you'll want a constructor that allocates memory for that pointer and a destructor that frees the allocated memory. However, if you have a class that only contains variables like "int a; float b; bool c", it's still a good idea to create a constructor that initializes everything, but a destructor is unnecessary.
Yeah, makes sense. I need to use constructors more in my code but I don't. I normally just let the defaults call and leave it at that.