草庐IT

typedeffing

全部标签

c++ - typedef-name 作为基类 : illegal but widely tolerated

[class.derived]的第一段说的是基类说明符,Ifthenamefoundisnotaclass-name,theprogramisill-formed.但是,一个simple测试表明Comeau和g++-ansi-pedantic都接受typedef-name作为基础。Boostheader上的简单grep-r'[^:]:mpl'表明流行的库通常依赖于这种行为。是否有任何编译器实际上拒绝了基说明符中类的typedef?GCC甚至检查基类类型是否不是const,这改进了非标准功能。有解决办法吗?我唯一能想到的就是用C++11别名模板替换typedef。一个模板化的别名声明声明

c++ - 返回 T<A> 的函数在某些 typedef 情况下无法编译

我不明白为什么func3()无法编译,当func2()和func4()做。g++4.1.2:error:'B::my_t'hasincompletetypeVS2008:errorC2079:'B::my_t'usesundefinedclass'A'templatestructC{Tmt_t;};templatestructB{typedefCC_type;Tmy_t;};structOther{};structA{Bfunc2();B::C_typefunc3();//error:'B::my_t'hasincompletetypeB::C_typefunc4();};intmai

c++ - 在函数上使用 typedef

在下文中,我如何使用typedef语法定义我的函数?typedefvoidF();//declaremyfunctionFf;//errorFf{} 最佳答案 函数的定义将遵循通常的语法://declaremyfunctionFf;//itisexactlyequivalentto:voidf();//definitionvoidf(){cout要测试该定义确实是之前声明的函数的定义,只需调用函数f()>after声明和before定义(阅读main()中的注释)://declarationFf;intmain(){f();//at

模板化类中 typedef 的 C++ 错误

我正在尝试编写一个简单的模板化事件调度程序,但我遇到了我不理解的编译器错误,搜索它也没有任何帮助。我正在使用VisualStudio2013Express。这是我的代码:templateclassEventDispatcher{public:typedefvoid(EventHandler)(Tevent);EventDispatcher(){}~EventDispatcher(){}voidaddListener(conststd::stringeventName,EventHandlerhandler){}voidfireEvent(Tevent){}private:typedef

c++ - Typedef、模板和 const 关键字

我在使用带有const关键字(用于函数参数类型)的模板时遇到问题,为了说明这一点,我创建了一个小代码:templatestructMethodCallerFactory{typedefReturnType(*Type)(ClassType*,Args...);templatestructMethod{staticTypecreateMethodCaller(){ReturnType(*caller)(ClassType*,Args...)=[](ClassType*obj,Args...args)->ReturnType{ReturnType(ClassType::*ptr)(Args

c++ - 这个 typedef 是如何工作的?

我正在看这个cpp闪电谈话video它在0:37显示这段代码template>classQScopedPointer{typedefT*QScopedPointer::*RestrictedBool;//howdoesthiswork?//whynotQScopedPointersinceQScopedPointerisatemplate?public:inlineoperatorRestrictedBool()const{returnisNull()?Q_NULLPTR:&QScopedPointer::d;}inlineboolisNull()const{return!d;}pro

c++ - 如何使用函数签名的 typedef 作为 std::function 的类型参数?

当用作模板类型参数时,函数的typedef和使用裸函数类型之间肯定有区别。即,考虑#includetypedefstd::functionTF1;typedefvoid(*FooFn)(int);typedefstd::functionTF2;intmain(){TF1tf1;TF2tf2;return0;}我可以创建TF1但不能创建TF2(错误:aggregate'TF2tf2'的类型不完整,无法定义)。(参见ideoneexample。)有没有办法使用函数(签名)的typedef作为模板类型参数;具体来说,作为std::function?的类型参数(没有C++11标记,因为我对bo

c++ - 模板化成员函数 typedef 无法编译

#include#includeusingnamespacestd;voidprintstr(conststring&s){coutclassTest{public:typedefvoid(*Func)(constA&);};typedefvoid(*Func)(conststring&);templatevoidbind(Test::Funcf,//在上面的代码中,我尝试使用另一个类中的函数指针typedef。如图所示,它没有编译,但是其他两行中的任何一行都没有注释,而不是Test::Funcf,。行,它编译得很好!这是我不能用C++做的事情吗?需要什么语法?使用g++4.4.3,我

c++ - std::vector 的 Typedef 和 ostream 运算符

我创建了一个Chromosome类,它最终只是一个带有ostream运算符的vector包装器,所以我决定改用typedefvector。但是,我在使用模板化的ostream运算符时遇到了问题……这是最好的方法吗?(我见过一些方法,但都没有奏效)templateclassChromosome{public:typedeftypenamestd::vectortype;typedeftypenamestd::pairptr_pair;};template//line19below:std::ostream&operator::type&chromosome){for(autoiter=c

c++ - 类中的typedef

有这样的代码:templateclassSomeClass{typedefboost::shared_ptrsPtr;typedefstd::vectorc;typedefc::iteratorcIt;//hereistheproblem};错误是:main.cpp:23:error:type‘std::vector,std::allocator>>’isnotderivedfromtype‘SomeClass’main.cpp:23:error:expected‘;’before‘cIt’如何在类中使用typedef来模板化参数?编辑:我想通了,对于g++,那一定是:typedeft