Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: using-declaration for non-member at class scope using std::cout

Tags:

c++

I downloaded a c++ project and was able to compile it using a makefile generated by cmake.

However when I try to add my own series of .h files in one of the .hh files of the project I start to get a million of errors, one of them being:

error: using-declaration for non-member at class scope using std::cout;

When the .h file that contains using std::cout is used elsewhere it works, but when added to this project it gives this error.

What can be the problem?

using std::cout;
using std::endl;
class TextManager : public FileManager {
    public:
        TextManager (const char * filename);
        void scanFile (Image &image, Scene &scene);
        void scanObjectModel (Image &image, Scene &scene);
        void getImageData (Image &image);
        void getMaterialData (Scene &scene);
        void getLightData (Scene &scene);
        void getSphereData (Scene &scene);
        void getPlaneData (Scene &scene);
        void getTriangleData (Scene &scene);
        int getLineValue (int size);
        void getLineValue2 (float (&lineNumbers) [10], Scene &scene, int &lineNumbersIndex);
        void getVerticesValues (int initPos, Scene &scene);  
        private:
   std::string line;
   float fractionaryTenPowers [6];
};

Problem solved. Was the lack of a bracket to close the declaration of one of the classes that was causing it.

like image 786
user2752471 Avatar asked Nov 14 '15 21:11

user2752471


1 Answers

The error means you've done this:

struct Foo {
  using std::cout;
  ...
};

That's not valid C++, in a class body you can only add a using-declaration for members of base classes, not arbitrary names.

You can only add using std::cout at namespace scope or inside a function body.

like image 163
Jonathan Wakely Avatar answered Nov 10 '22 02:11

Jonathan Wakely