• Advertisement
Sign in to follow this  

weird error

This topic is 4713 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I get this error when I compile this code: 3 C:\Program Files\Dev-Cpp\Blackjack Game\blackjack.cpp In file included from C:/Program Files/Dev-Cpp/Blackjack Game/blackjack.cpp
#include <iostream>
#include "deck.cpp"
#include "hand.cpp"

using namespace std;

int main(int argv, char *argc[])
{
    system("PAUSE");
    return 0;
}

hand.cpp

#include <vector>
#include <string>

template <class T> class hand {
         
         // interface
         public:
                typedef typename std::vector<T>::iterator iterator;
                typedef typename std::vector<T>::const_iterator const_iterator;
                typedef typename std::vector<T>::size_type size_type;
                
                // get size of hand
                size_type size() const {
                       return v.size(); }
                
                // get total value of hand
                int value() const {
                       int count = 0;
                       for (iterator i = begin(); i != end(); i++)
                           count += i->value;
                       return count; }
                
                // change value of card in hand if its the right card
                void change_card(iterator card, int new_value, std::string card_name) {
                       if (card->name == card_name)
                            card->value = new_value; }
                
                // add cards to the hand
                // invalidates existing pointers
                void add(T card) {
                     v.pushback(card); }
                
                // iterator corresponding to beginning of hand
                iterator begin() {
                       return v.begin(); }
                const_iterator begin() const {
                       return v.begin(); }
                       
                // iterator corresponding to end of hand
                iterator end() {
                       return v.end(); }
                const_iterator end() const {
                       return v.end(); }
                
         private:
                 // vector is used to manage hand
                 std::vector<T> v;       };

I've got no idea why im getting this error. the #include "deck.cpp" doesnt give me this error so why does hand? I am using dev-cpp as compiler

Share this post


Link to post
Share on other sites
Advertisement
Is it legal to include "*.cpp" files like you have in your code. I've tried it before and it throws errors like a hoe. Try just making your hand.cpp into a header file.

toXic1337

Share this post


Link to post
Share on other sites
changing hand to a header file didnt work. I still got the same error.

Edit:

I just tried compiling blackjack.cpp with the microsoft compiler with an added line to output "text" and it worked, maybe its just dev-cpp...

Share this post


Link to post
Share on other sites
Can you post the complete message of the output. The "In file included from " is usually just a warning, scroll down and see if there is something else below that message.

Share this post


Link to post
Share on other sites
In your post, I don't think you put what the actual error is unless the error is, "3 C:\Program Files\Dev-Cpp\Blackjack Game\blackjack.cpp
In file included from C:/Program Files/Dev-Cpp/Blackjack Game/blackjack.cpp" which doesn't look like an error to me. What is the error it gives you?

Share this post


Link to post
Share on other sites
Quote:
Original post by xidis
changing hand to a header file didnt work. I still got the same error.


Did you also change "deck.cpp"?

Share this post


Link to post
Share on other sites
Heres what the compile log had in it:

Compiler: Default compiler
Executing g++.exe...
g++.exe "C:\Program Files\Dev-Cpp\Blackjack Game\blackjack.cpp" -o "C:\Program Files\Dev-Cpp\Blackjack Game\blackjack.exe" -I"C:\Program Files\Dev-Cpp\include\c++\3.3.1" -I"C:\Program Files\Dev-Cpp\include\c++\3.3.1\mingw32" -I"C:\Program Files\Dev-Cpp\include\c++\3.3.1\backward" -I"C:\Program Files\Dev-Cpp\lib\gcc-lib\mingw32\3.3.1\include" -I"C:\Program Files\Dev-Cpp\include" -L"C:\Program Files\Dev-Cpp\lib"
In file included from C:/Program Files/Dev-Cpp/Blackjack Game/blackjack.cpp:3:

C:/Program Files/Dev-Cpp/Blackjack Game/hand.cpp:66:44: warning: no newline at end of file
C:/Program Files/Dev-Cpp/Blackjack Game/blackjack.cpp:12:2: warning: no newline at end of file

Execution terminated
Compilation successful
____________
I tried compiling with the microsoft compiler and it worked. I didnt use that compiler before cause it uses the console and dev-cpp is easier.

Share this post


Link to post
Share on other sites
I know some compilers include things differently, but I never heard of not being able to include a cpp instead of h file. Rather, most classes use h files for the declarations and cpp files for the definitions. In the h file
int Main(); In the cpp file int Main(){ //Whatever you do};

Share this post


Link to post
Share on other sites
i think i just figured it out, i think that first error is really an error, its just telling that there is a warning in the hand.cpp class for no newline

btw, what does that warning mean and how do i get rid of it?

Share this post


Link to post
Share on other sites
It is perfectly legal to include .cpp files - see, there's a dirty secret here: the bit of code that handles those lines that say "#include" or "#pragma" or whatever - doesn't have any concept of the language. It just sees text. It is very, very dumb, and completely separate from the compiler. The fact that it's needed (or at least, really useful) at all is one of the main things that reflects badly on the C and C++ languages.

However, it is a very bad idea to do things that way, and not hard to learn how to do things properly. Read here. Learn.

Anyway.

"In file included from C:/Program Files/Dev-Cpp/Blackjack Game/blackjack.cpp"

is not a complete error message. Most C and C++ compilers have no problem with giving you an message that is several lines - even several screens at times - long. You have to extract the whole error message for anyone to be able to help you with it. You can tell this is not a complete error message because, well, it's not a complete sentence: "In the file included from here,"... ok, what about it?

Anyway, "no newline at end of file" means exactly what it sounds like. There is no newline (return character) at the end of the file. This is being reported as an error, therefore such a newline is required. Solution, put one there.

See, understanding the compiler is easy (most of the time). :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement