Find the answer to your Linux question:
Results 1 to 2 of 2
I've stripped these files down as much as possible to illustrate the problem. I have matrix.cpp and matrix.h, and although the G++ -E output shows that the file is being ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2010
    Posts
    31

    Very Strance C++ Problem ( wont #include )


    I've stripped these files down as much as possible to illustrate the problem. I have matrix.cpp and matrix.h, and although the G++ -E output shows that the file is being included, it insists that the class in matrix.cpp hasn't been declared.

    if I manually paste the h file's contents into the cpp instead of using the include, it works properly...

    matrix.h
    Code:
    class Mat4f {
    public:
        Mat4f( void );
    
        void LoadIdentity( void );
    
    
    public:
        float data[4][4];
    };
    matrix.cpp
    Code:
    #include "matrix.h"
    
    Mat4f::Mat4f( void ) {
        LoadIdentity();
    }
    output of g++ matrix.cpp
    Code:
    $ g++ matrix.cpp 
    matrix.cpp:3:1: error: ‘Mat4f’ does not name a type
    output of g++ -v
    Code:
    Using built-in specs.
    COLLECT_GCC=g++
    COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/4.6.1/lto-wrapper
    Target: i686-linux-gnu
    Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.1-9ubuntu3' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++,go --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
    Thread model: posix
    gcc version 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3)
    ( I'm on mint, not ubuntu :P )

  2. #2
    Just Joined!
    Join Date
    Aug 2010
    Posts
    31
    okay, apparently I just cant name my header file matrix.h, because it ends up including some other matrix.h file somewhere else. strange.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •