help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "conflicting declaration" of a typedef for std::vector


From: Andre Poenitz
Subject: Re: "conflicting declaration" of a typedef for std::vector
Date: Fri, 12 Dec 2008 20:05:39 +0100
User-agent: tin/1.9.3-20080506 ("Dalintober") (UNIX) (Linux/2.6.27-7-generic (i686))

dave.rudolf@usask.ca wrote:
> Hi folks,

Hi Dave.
 
> I have a very simple set-up that is giving me grief. In one header
> file, I have the following types defined:
> 
>    #include <vector>
> 
>    struct Point {
>      int frameNum;
>      float x, y, z;
>    };
> 
> 
>    typedef std::vector< Point > Frame;
>    typedef std::vector< Frame > Capture;
> 
> 
> Then, in another header, I want to use this type, but not actually
> have to include the header (just for dependency simplification), so I
> have
> 
>    class Capture; // forward declaration
>    class Vector; // forward declaration
> 
>    bool generateCentroid( const Capture& capture, int frameNumber,
> Vector& posOut );
> 
> However, I get the following error when I do so:
> 
> 
> points.h:14: error: conflicting declaration 'typedef class
> std::vector<std::vector<Point, std::allocator<Point> >,
> std::allocator<std::vector<Point, std::allocator<Point> > > > Capture'
> pointutils.h:7: error: 'struct Capture' has a previous declaration as
> 'struct Capture'
> 
> I'm not sure exactly what it is complaining about, other than it maybe
> doesn't like to match my forward declaration of Capture with the
> typedef of a vector of a vector, or something like that. Can anyone
> spot my mistake?

A typedef does not create a new type. It's basically just a new name for
an existing one. 'class Capture;' declares a class that's different
from 'std::vector< Frame >'.

A possible way to get part of the cake and eat it is the following"

    #include <vector>
 
    struct Point {
      int frameNum;
      float x, y, z;
    };
 

    class Capture : public std::vector< Frame > {};

This is a class that can be forward-declared by 'class Capture;'
but is not an exact substitute, and sometimes clumsy to you (you'd
need to re-implement all constructors for instance).
 
Andre'


reply via email to

[Prev in Thread] Current Thread [Next in Thread]