#### Archived

This topic is now archived and is closed to further replies.

# this is weird....

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

## Recommended Posts

heres a weird problem ive never seen before i have a Monster.hpp file that defines a class but doesnt impliment the functions and i have a Monster.cpp file that defines all the functions and such now i include the Monster.cpp file in the main cpp file( which is main) and in the Monster.cpp file i include Monster.hpp but i get some weird errors like this: 16 monster.cpp implicit declaration of function int rand(...)'' 52 monster.cpp cin'' undeclared (first use this function) 62 monster.cpp cout'' undeclared (first use this function) these errors arise in Monster.cpp can anyone tell me whats wrong plz?

##### Share on other sites
First of all, don't include a .cpp file into another .cpp file!
The proper way of doing what you're (probably) trying to do, is to compile each .cpp file separately and then *link* them together (Read the docs for your compiler and linker if you don't understand what I'm talking about).

Now, to your problem: Most likely you haven't included the correct header-files.

'cin' and 'cout' are defined in "iostream.h" (or "iostream").
The 'rand' function is defined in "stdlib.h" (or "cstdlib").

[EDIT: Spelling mistakes]

Edited by - Dactylos on September 22, 2001 8:01:51 PM

##### Share on other sites
i have all the correct files in the main file
im not stupid enough to forget them

i am on the other hand stupid enough to include a cpp in another cpp

##### Share on other sites
Make the hpp file a .h file instead.

I dont think that makes a difference but it is the .. right(?) way to do it.

"I''ve sparred with creatures from the nine hells themselves... I barely plan on breaking a sweat here, today."~Drizzt Do''Urden

##### Share on other sites
but if im making a C++ project shouldn''t I make a hpp file instead of h?

the help file that comes with Dev C++( the ide I use) doesnt contain a very umm good docs

maybe i didnt look hard enough

if anyone has Dev C++ and has encountered this problem can you plz enlighten me

##### Share on other sites
Perhaps you included the headers in the wrong order (i.e. including Monster.cpp first, and then the stdlib.h and iostream.h headers? (Of course then the problem would go away if you no longer include Monster.cpp in main.cpp)

(If I am pointing out the obvious, or seem patronizing, it's only because I don't know what level you're on )

Giving C++ headers a .hpp extension is perfectly valid/standard.

usual C++ file extensions:
.C     (only usable on systems where case matters in filenames)
.cc
.cpp
.cxx

.h
.hpp
.hxx

Edited by - Dactylos on September 22, 2001 8:01:30 PM

##### Share on other sites
If you did ''#include <iostream>'' rather than ''#include <iostream.h>'', you''ll need to resolve the namespace (cout and cin are now part of the std namespace):
#include using namespace std;cout << "This sucka''ll work" << endl; 

OR
#include std::cout << "This works too." << endl; 

or, alternatively
#include cout << "This uses the older headers for backwards compatibility. Start moving to the new method (above)." << endl; `

##### Share on other sites
im not that big of a newb to not know these things

ive done everything right in terms of header files and their order

these things have never happened in the +1 years ive used Dev C++

im trying to do wat dac said and find out how to link the dam cpp files together but i cant find anything in the help files

##### Share on other sites
Dev-C++ is an IDE, right? What compiler are you using. I''ll assume for a moment that it''s gcc/DJGPP. If that''s the case, I believe the link command is ''link''. However, the ''gcc'' command automatically handles that step if a bunch of .cpp and/or .o files are passed to it with the appropriate parameter, and you IDE probably already resolves. What you should look into is how to create projects/project workspaces with Dev-C++, so the IDE can know to link all the files together.

##### Share on other sites
uhh its the mingw compiler( i think)

1. 1
2. 2
frob
15
3. 3
Rutin
12
4. 4
5. 5

• 13
• 12
• 58
• 14
• 15
• ### Forum Statistics

• Total Topics
632124
• Total Posts
3004236

×