在类中使用类。 [英] using a class inside a class.
问题描述
我做了一些在线搜索,我找不到任何参考资料
。
我使用的是MinGW,gcc 4.3和am有以下编辑
问题:
类CFoo
{
public:
...
私人:
std :: list< CFoom_children;
};
>
来自编译器的投诉如下:
c:\\\ nyw; \\ bin \ ../ lib / gcc / i386-pc-mingw32 / 4.3。 0 / include / c ++ / bits /
boost_concept_check.h:实例化
''__ gn_cxx :: _ SGIAssignableConcept< CFoo>'':
c:\ editw\bin\ ../ lib / gcc / i386-pc-mingw32 / 4.3.0 / include / c ++ / bits /
stl_list.h:420:从'实例化' 'std :: list< CFoo,
std :: allocator< CFoo''
c:\mingw\bin\ ../ lib / gcc / i386- pc-mingw32 / 4.3.0 / include / c ++ / bits /
boost_concept_check.h:216:错误:
''__ nuu_cxx :: _ SGIAssignableConcept< _Tp> :: __ a''具有不完整的类型
所以,基本上,我认为它的含义是它不知道如何
构建类,因为在尝试创建它时,CFoo还没有被定义(即
)不完整的类型)。我尝试添加
" std :: list< class CFoo>"同样,但这也没有奏效。这个
在视觉工作室上编辑了一些警告。
我可以通过制作std :: list< CFoo *>来完成这项工作。 ,但是我很想知道是否有办法让这个按照定义工作。
感谢收听。
-phil
I did some searching online and i couldn''t find anything in reference
to this.
I am using MinGW, gcc 4.3 and am having the following compilation
issue:
class CFoo
{
public:
...
private:
std::list<CFoom_children;
};
The complaint from the compiler looks like this:
c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
boost_concept_check.h: In instantiation of
''__gnu_cxx::_SGIAssignableConcept<CFoo>'':
c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
stl_list.h:420: instantiated from ''std::list<CFoo,
std::allocator<CFoo''
c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
boost_concept_check.h:216: error:
''__gnu_cxx::_SGIAssignableConcept<_Tp>::__a'' has incomplete type
So, basically, I think what it''s saying is that it doesn''t know how to
build the class because CFoo hasn''t been defined by the time it''s
trying to create it (i.e. incomplete type). I tried adding
"std::list<class CFoo>" as well, but that didn''t work either. This
compiles on visual studio with some warnings.
I can make this work by making it "std::list<CFoo*>", but I''m
wondering if there''s a way to get this to work as defined.
thanks for listening.
-phil
推荐答案
ph ************** @ gmail.com 写道:
I做了一些在线搜索,我找不到任何参考资料
到这个。
我正在使用MinGW,gcc 4.3并且正在进行以下编译
发行:
class CFoo
{
public:
...
私人:
std :: list< CFoom_children;
};
编译器的抱怨如下:
c:\mingw\bin\ ../ lib / gcc / i386-pc-mingw32 / 4.3.0 / include / C ++ /位s /
boost_concept_check.h:实例化
''__ gn_cxx :: _ SGIAssignableConcept< CFoo>'':
c:\mingw \\ \\ bin \ ../ lib / gcc / i386-pc-mingw32 / 4.3.0 / include / c ++ / bits /
stl_list.h:420:从''std :: list<实例化CFoo,
std :: allocator< CFoo''
c:\\\ nyw; \\ bin \ ../ lib / gcc / i386-pc-mingw32 / 4.3。 0 / include / c ++ / bits /
boost_concept_check.h:216:错误:
''__ gn_cxx :: _ SGIAssignableConcept< _Tp> :: __ a''类型不完整
所以,基本上,我认为它的含义是它不知道如何构建这个类,因为CFoo还没有是在它试图创造它的时候定义的(即不完整的类型)。我尝试添加
" std :: list< class CFoo>"同样,但这也没有奏效。这个
在视觉工作室上编辑了一些警告。
我可以通过制作std :: list< CFoo *>来完成这项工作。 ,但是我很想知道是否有办法让这个按规定工作。
感谢收听。
I did some searching online and i couldn''t find anything in reference
to this.
I am using MinGW, gcc 4.3 and am having the following compilation
issue:
class CFoo
{
public:
...
private:
std::list<CFoom_children;
};
The complaint from the compiler looks like this:
c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
boost_concept_check.h: In instantiation of
''__gnu_cxx::_SGIAssignableConcept<CFoo>'':
c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
stl_list.h:420: instantiated from ''std::list<CFoo,
std::allocator<CFoo''
c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
boost_concept_check.h:216: error:
''__gnu_cxx::_SGIAssignableConcept<_Tp>::__a'' has incomplete type
So, basically, I think what it''s saying is that it doesn''t know how to
build the class because CFoo hasn''t been defined by the time it''s
trying to create it (i.e. incomplete type). I tried adding
"std::list<class CFoo>" as well, but that didn''t work either. This
compiles on visual studio with some warnings.
I can make this work by making it "std::list<CFoo*>", but I''m
wondering if there''s a way to get this to work as defined.
thanks for listening.
我可以告诉你的是我在过去已经完成了同样的事情
在Microsoft Visual C ++ .net中都成功了2003和DevC ++。这是
在Microsoft Visual C ++中成功编译的东西.net 2003:
#include< list>
class CFoo
{
private:
std :: list< CFoom_children;
};
int main()
{
CFoo Foo;
}
>
没有警告,没有错误。
我不知道为什么你的gcc版本在抱怨,我不认为它
应该,AFAIK这是完全合法的,虽然我没有读过它的标准
。
-
Jim Langston
ta*******@rocketmail.com
这就是我在尝试编译代码时得到的结果:
C:\> type foo.cpp
#include< list>
class CFoo
{
private:
std :: list< CFoom_children;
};
int main()
{
CFoo Foo;
}
C:\> gcc -v
使用内置规格。
目标:i386-pc-mingw32
配置:../gcc-4.3.0/configure --prefix = / mingw --disable-nls
--enable-languages = c,c ++,fortran,objc,obj-c ++,ada,
java --disable-win32-registry --disable-sjlj-exceptions --enable-
libstdcxx-debug --enable-version-specific-runtime-libs
--with-gmp = / mingw / src / gcc / gmp-mpfr-root --with-mpfr = / mingw / src / gcc / gmp-
mpfr- root --enable-libgcj --enable-concept-checks
--enable-shared
线程模型:win32
gcc版本4.3。 0(GCC)
C:\> gcc -o foo foo.cpp
c:\ ingw\bin\ ../ lib /gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
boost_concept_check.h:实例化''__gnu_cxx :: _ S
GIAssignableConcept< CFoo>'':
c:\ ingw\bin\ .. /lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
stl_list.h:420:从''std :: list< CFoo,std:
:allocator< CFoo''
foo.cpp:6:从这里实例化
c:\mingw\bin\ ../ lib /gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
boost_concept_check.h:216:错误:''__ nuu_cxx :: _ SGIAssigna
bleConcept< ; _Tp> :: __ a''具有不完整的类型
foo.cpp:4:错误:''类CFoo'的前向声明'
c:\\\ ningw \ bin \ ../ lib / gcc / i386-pc-mingw32 / 4.3.0 / include / c ++ / bits /
boost_concept_check.h:在成员函数''void __gnu_cxx
:: _ SGIAssignableConcept< _Tp> :: __ constraints()[with _Tp = CFoo]'':
c:\mingw\bin\ ../ lib / gcc / i386-pc -mingw32 / 4.3.0 / include / c ++ / bits /
stl_list.h:420:从''std :: list< CFoo实例化,std:
:allocator< ; CFoo''
foo.cpp:6:instantia从这里开始
c:\ ingw\bin\ ../ lib / gcc / i386-pc-mingw32 / 4.3.0 / include / c ++ / bits /
boost_concept_check.h:208:错误:使用无效字段''__
gnu_cxx :: _ SGIAssignableConcept< _Tp> :: __ a''
c:\mingw\bin \ ../ lib / gcc / i386-pc-mingw32 / 4.3.0 / include / c ++ / bits /
boost_concept_check.h:209:错误:使用无效字段''__
gnu_cxx :: _ SGIAssignableConcept< _Tp> :: __ a''
c:\ ingw\bin\ ../ lib / gcc / i386-pc-mingw32 / 4.3.0 / include / c ++ / bits /
boost_concept_check.h:209:错误:使用无效字段''__
gnu_cxx :: _ SGIAssignableConcept< _Tp> :: __ a''
c:\\\ tnw \ bin \ ../ lib / gcc / i386-pc-mingw32 / 4.3.0 / include / c ++ / bits /
stl_list.h :420:从''std :: list< CFoo实例化,std:
:allocator< CFoo''
foo.cpp:6:从这里实例化
c:\mingw\bin\ ../ lib / gcc / i3 86-pc-mingw32 / 4.3.0 / include / c ++ / bits /
boost_concept_check.h:210:错误:使用无效字段''__
gnu_cxx :: _ SGIAssignableConcept< ; _Tp> :: __ a''
c:\\\ tnw \ bin \ ../ lib / gcc / i386-pc-mingw32 / 4.3.0 / include / c ++ / bits /
boost_concept_check.h:在成员函数''void __gnu_cxx
:: _ SGIAssignableConcept< _Tp> :: __ const_constraints(const _Tp&)[with
_Tp = CFoo]'':
c:\ ingw\bin\ ../ lib / gcc / i386-pc-mingw32 / 4.3.0 / include / c ++ / bits /
boost_concept_check.h:210:从''void __gn
u_cxx :: _ SGIAssignableConcept< _Tp> :: __ constraints()[with _Tp = CFoo]''
$ b实例化$ bc:\\\ twid \\\ n \ n .. / lib / gcc / i386-pc-mingw32 / 4.3.0 / include / c ++ / bits /
stl_list.h:420:实例化自''std :: list< CFoo,std:
:allocator< CFoo''
foo.cpp:6:从这里实例化
c :\mingw\bin \ ../ lib / gcc / i386-pc-mingw32 / 4.3.0 / include / c ++ / bits /
boost_concept_check.h:214:错误:使用无效字段''__
gnu_cxx :: _ SGIAssignableConcept< _Tp> :: __ a''
C:\>
Here''s exactly what i get when I try to compile that code:
C:\>type foo.cpp
#include <list>
class CFoo
{
private:
std::list<CFoom_children;
};
int main()
{
CFoo Foo;
}
C:\>gcc -v
Using built-in specs.
Target: i386-pc-mingw32
Configured with: ../gcc-4.3.0/configure --prefix=/mingw --disable-nls
--enable-languages=c,c++,fortran,objc,obj-c++,ada,
java --disable-win32-registry --disable-sjlj-exceptions --enable-
libstdcxx-debug --enable-version-specific-runtime-libs
--with-gmp=/mingw/src/gcc/gmp-mpfr-root --with-mpfr=/mingw/src/gcc/gmp-
mpfr-root --enable-libgcj --enable-concept-checks
--enable-shared
Thread model: win32
gcc version 4.3.0 (GCC)
C:\>gcc -o foo foo.cpp
c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
boost_concept_check.h: In instantiation of ''__gnu_cxx::_S
GIAssignableConcept<CFoo>'':
c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
stl_list.h:420: instantiated from ''std::list<CFoo, std:
:allocator<CFoo''
foo.cpp:6: instantiated from here
c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
boost_concept_check.h:216: error: ''__gnu_cxx::_SGIAssigna
bleConcept<_Tp>::__a'' has incomplete type
foo.cpp:4: error: forward declaration of ''class CFoo''
c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
boost_concept_check.h: In member function ''void __gnu_cxx
::_SGIAssignableConcept<_Tp>::__constraints() [with _Tp = CFoo]'':
c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
stl_list.h:420: instantiated from ''std::list<CFoo, std:
:allocator<CFoo''
foo.cpp:6: instantiated from here
c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
boost_concept_check.h:208: error: using invalid field ''__
gnu_cxx::_SGIAssignableConcept<_Tp>::__a''
c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
boost_concept_check.h:209: error: using invalid field ''__
gnu_cxx::_SGIAssignableConcept<_Tp>::__a''
c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
boost_concept_check.h:209: error: using invalid field ''__
gnu_cxx::_SGIAssignableConcept<_Tp>::__a''
c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
stl_list.h:420: instantiated from ''std::list<CFoo, std:
:allocator<CFoo''
foo.cpp:6: instantiated from here
c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
boost_concept_check.h:210: error: using invalid field ''__
gnu_cxx::_SGIAssignableConcept<_Tp>::__a''
c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
boost_concept_check.h: In member function ''void __gnu_cxx
::_SGIAssignableConcept<_Tp>::__const_constraints( const _Tp&) [with
_Tp = CFoo]'':
c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
boost_concept_check.h:210: instantiated from ''void __gn
u_cxx::_SGIAssignableConcept<_Tp>::__constraints() [with _Tp = CFoo]''
c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
stl_list.h:420: instantiated from ''std::list<CFoo, std:
:allocator<CFoo''
foo.cpp:6: instantiated from here
c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
boost_concept_check.h:214: error: using invalid field ''__
gnu_cxx::_SGIAssignableConcept<_Tp>::__a''
C:\>
ph ************** @ gmail.com 写道:
这就是我在尝试编译代码时得到的结果:
C:\\ \\>输入foo.cpp
#include< list>
class CFoo
{
private:
std :: list< CFoom_children;
};
int main()< br $>
{
CFoo Foo;
}
C:\> gcc -o foo foo.cpp
c:\\\ nyw; \\ bin \ ../ lib / gcc / i386-pc-mingw32 / 4.3.0 / include / c ++ / bits /
boost_concept_check.h:实例化''__gnu_cxx :: _ S
GIAssignableConcept< CFoo>' :
Here''s exactly what i get when I try to compile that code:
C:\>type foo.cpp
#include <list>
class CFoo
{
private:
std::list<CFoom_children;
};
int main()
{
CFoo Foo;
}
C:\>gcc -o foo foo.cpp
c:\mingw\bin\../lib/gcc/i386-pc-mingw32/4.3.0/include/c++/bits/
boost_concept_check.h: In instantiation of ''__gnu_cxx::_S
GIAssignableConcept<CFoo>'':
< snip>
看起来您的编译器配置不正确,请尝试使用gcc组。
-
Ian Collins。
<snip>
Looks like your compiler isn''t configured correctly, try a gcc group.
--
Ian Collins.
这篇关于在类中使用类。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!