Skip to main content
gamedev.net
🔒 Locked

Forward declarations

Started by kelaklub Jun 17, 2007 at 11:32 AM 2 replies 550+ views
Original Post
kelaklub
kelaklub
The following was compiled with g++ (GCC) 3.4.2 (mingw-special). The error message that I get upon compilation is ... error: aggregate `nmEzGeom::clVector_3d vec' has incomplete type and cannot be defined It has happening in the call from the getVectorX() function inside the point class. I have no idea on how to resolve this error. I think it has something to do with the forward declaration of the vector class in the point class, but I'm not sure. Any advice would be appreciated. Thanks.
[SOURCE]
//
// main.cpp
//
#include "clPoint_3d.h"
#include "clVector_3d.h"

using namespace nmEzGeom;

int main()
{
    return 0;
}

[/SOURCE]
[/source][/source]
[SOURCE]
//
// clPoint_3d.h
//
#pragma once

namespace nmEzGeom
{
    // Forward declaration to access the 3d vector class.
    class clVector_3d;

    class clPoint_3d
    {
    protected:
        //
        // Member Variables
        //
        double point_3d[4];

    public:
        clPoint_3d(); // Default Constructor
        inline const double getVectorX() const; // getVectorX
    };

    // *************************************************************************
    // Default Constructor
    // *************************************************************************
    clPoint_3d::clPoint_3d()
    {
        this->point_3d[0] = 0.0; // x
        this->point_3d[1] = 0.0; // y
        this->point_3d[2] = 0.0; // z
        this->point_3d[3] = 1.0; // w
    }

    // *************************************************************************
    // getVectorX
    // *************************************************************************
    inline const double clPoint_3d::getVectorX() const
    {
        clVector_3d vec;
        return vec.getX();
    }

} // nmEzGeom

[/SOURCE]
[/source][/source]
[SOURCE]
//
// clVector_3d.cpp
//
#pragma once

namespace nmEzGeom
{
    class clVector_3d
    {
    protected:
        double vector_3d[4];

    public:
        clVector_3d(); // Default Constructor
        inline const double getX() const; // getX
    };

    // *************************************************************************
    // Default Constructor
    // *************************************************************************
    clVector_3d::clVector_3d()
    {
        this->vector_3d[0] = 0.0; // x
        this->vector_3d[1] = 0.0; // y
        this->vector_3d[2] = 0.0; // z
        this->vector_3d[3] = 0.0; // w
    }

    // *************************************************************************
    // getX
    // *************************************************************************
    inline const double clVector_3d::getX() const
    {
        return this->vector_3d[0];
    }

} // nmEzGeom

[/SOURCE]
[/source][/source]
Verg
Verg
The problem is you're trying to instantiate an incomplete type "clVector_3d" inside your header file.

    inline const double clPoint_3d::getVectorX() const    {        clVector_3d vec;        return vec.getX();    }

You need to move that code into a source file (.cpp) and include the header that defines the "clVector_3d" class there.
kelaklub
kelaklub
Okay. Initially I had this class created as a template class and it compiled fine. I guess it's because the templates need to have their implementations in the same header file. When I made it non-template the compiler started screaming. Thanks for all the help.
Verg
Verg
Quote:
Original post by kelaklub
Okay. Initially I had this class created as a template class and it compiled fine. I guess it's because the templates need to have their implementations in the same header file. When I made it non-template the compiler started screaming. Thanks for all the help.


Pretty much. The point is the template code wouldn't have been instantiated in the header anyway; it would get instantiated where you first reference that template function.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.