-3

Firstly, I have looked all over for solutions and I can't seem to fix it. When trying to compile source code I get the following error.

g++ -c -I/home/jcallahan/ACM/include/FANSI -I/home/jcallahan/ACM/FourtyTwo/Base -I/home/jcallahan/ACM/FourtyTwo/FunctionSpaces -I/home/jcallahan/ACM/FourtyTwo/MeshLib LagrangeFunctions.cpp In file included from /home/jcallahan/ACM/include/FANSI/MatrixVector.h:6:0, from LagrangeFunctions.cpp:17: /home/jcallahan/ACM/include/FANSI/Matrix.h:184:24: error: ‘ostream’ has not been declared void WriteToTextFile(ostream &) ;

The error is coming from the included Matrix.h and Vector.h (I have more of these errors only showing one). I believe the error is within Matrix.h/Vector.h. The code is cut off because I do not think that the classes member functions have anything to do with it.

#include "AbstractMatrix.h"

class Matrix : public AbstractMatrix
{
  friend std::ostream &operator<<(std::ostream &,const Matrix &) ;
  friend std::istream &operator>>(std::istream &, Matrix &) ;
 public:

Anyone have any clue what is going on or how I can fix it? For additional info I am using the g++ compiler.

jgCallahan
  • 33
  • 1
  • 4
  • 1
    add `#include ` to the top of your file – Mgetz Dec 17 '13 at 20:55
  • 1
    It seems that one of your headers uses `ostream` without qualification (`std::`) and without a suitable `using` declaration or `using` directive. Independent of the qualification a suitable header (`` or ``) may also be missing. – Dietmar Kühl Dec 17 '13 at 20:57
  • Mgetz, I added in the include and it didn't change anything. Dietmar, I do not have a "using namespace std" in any of my headers but only this one gives me a problem. Also when compiling using PGI compilers it compiles without an issue – jgCallahan Dec 17 '13 at 21:00
  • @user2584732: the error message quoted by thecompiler is certainly missing `std::`. Based on what you posted other things may be missing, too. – Dietmar Kühl Dec 17 '13 at 21:03
  • The class member function code is *clearly* something to do with it: the line that is the problem is the line given in the error message, which is the declaration of method `void WriteToTextFile(ostream &)`. *Read your error message* before posting. It should be `void WriteToTextFile(std::ostream &)`. – Dan Puzey Dec 18 '13 at 08:31
  • I'm not sure I agree with the duplicate here. That one was (only) about not qualifying the namespace in which the symbol resides. This one is (also) about simply not including the declaration of the symbol in the first place. – underscore_d Oct 25 '17 at 20:58

1 Answers1

2

The file you posted should include this line:

#include <iostream>

Also, the error message includes this definition:

void WriteToTextFile(ostream &) ;

That needs to be changed to std::ostream like the others.

s4y
  • 50,525
  • 12
  • 70
  • 98
  • In the header file? I thought it was a no-no to put them in header files? – jgCallahan Dec 17 '13 at 20:57
  • You probably confused the no-no with `using namespace std;`, which _is_ a no-no to put in header files. –  Dec 17 '13 at 21:00
  • It's not a no-no. One of the declarations uses `std::ostream`, so it’s pretty essential to include it. – s4y Dec 17 '13 at 21:01
  • I added in the #include to the header file and it didn't change the error. – jgCallahan Dec 17 '13 at 21:01
  • You added it above this definition, right? Which is line 184 of `Matrix.h`? – s4y Dec 17 '13 at 21:03
  • Ah, sorry, missed something the first time: The error message includes the problematic definition: `void WriteToTextFile(ostream &) ;`. That should be `std::ostream`. EDIT: updated my answer. – s4y Dec 17 '13 at 21:04
  • Yes, I added it on line 42. – jgCallahan Dec 17 '13 at 21:04
  • That fixed it Sidnicious. Any way to apply that without having to add it before it for every function? – jgCallahan Dec 17 '13 at 21:06
  • I am just being lazy. I will just use emacs to find and replace all. Thank you everyone – jgCallahan Dec 17 '13 at 21:08
  • Nice! In header files, you do usually use full names. But, in the header file or in your class definition you could use `using std::ostream;` to bring it into your namespace. – s4y Dec 17 '13 at 21:09
  • Thank you again for your help. Teaching myself c++ and was hung up on this for a week trying to figure it out myself. – jgCallahan Dec 17 '13 at 21:15