由买买提看人间百态

topics

全部话题 - 话题: typedef
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
T*******x
发帖数: 8565
1
来自主题: Programming版 - c++ typedef 一问
读typedef的trick是这样的:
你先把typedef这个关键字去掉,这个语句就变成了一个变量声明,
再加回typedef,就定义了一个这个变量所属的类型。
比如你这个
typedef void(Receiver::* Action)();
去掉这个typedef,就是一个函数指针变量的声明,
这个指针指向一个函数,这个函数1.没有参数2.没有返回值3.有一定的scope --
必须指向一个成员函数。加回typedef后,就定义了一个相应的类型。
请注意这两个的不同:
void func();
void (*func)();
前者是一个函数的prototype,后者是一个函数指针变量的声明,
我们这里要得是后者(去掉typedef之后)。
j******o
发帖数: 35
2
来自主题: Programming版 - C 中的typedef 一问
友好的typedef
C语言允许我们自己定义新的数据类型,其语法很简单,例如:
typedef int INT32;
INT32 a; //相当于int a
INT32 *p; //相当于int *p
可以看出,如果想用一个新的名字XXX代表一种数据类型,只要声明一个这种数
据类型的变量,变量名是XXX,并在语句的最前面加上“typedef”关键字即可。
例如:
我们想建立String数据类型,它其实是char *,
第一步,声明一个char*变量String:
char* String;
第二步,加上typedef:
typedef char *String;
这样,从现在开始我们就可以用String表示char*,例如:
String fileName;
int main(int argc, String argv[]){}
在使用typedef的过程中要注意两点:
yy
发帖数: 45
3
来自主题: Programming版 - c++ typedef 一问
看了看一些source code, 有一些typedef读起着实比较费劲,
比如:
template
class SimpleCommand: public Command{
public:
typedef void (Receiver::* Action)();
SimpleCommand(Receiver* r, Action a):
_receiver(r), _action(a){}
virtual void Execute();
private:
Action _action;
Receiver* _receiver;
}
请问有什么比较简单的trick或者rule 来读这个 typedef
typedef void (Receiver::* Action)();
谢谢
B********e
发帖数: 1062
4
来自主题: Programming版 - C++ question about template typedef
template
struct MapofVec{
typedef vector VecType;
typedef typename vector::iterator VecIter;
typedef map MapType;
typedef typename map::iterator MapIter;
};

use
**
w******g
发帖数: 67
5
来自主题: Programming版 - C++ question about template typedef
Thanks a lot. Another question: if I want to define a function template to
print out the elements of the MapOfVec.
template
struct MapOfVec
{
typedef vector VecType;
typedef typename vector::iterator VecIter;
typedef map MapType;
typedef typename map::iterator MapIter;
};
template
void printElems_MapOfVec(const MapOfVec::MapType& map);
It a
B********e
发帖数: 1062
6
来自主题: Programming版 - C++ question about template typedef
This may work.
template
class MapOfVec{
public:
typedef vector VecType;
typedef typename vector::iterator VecIter;
typedef map MapType;
typedef typename map::iterator MapIter;
void print(MapType& map);
};

agian.
X****r
发帖数: 3557
7
来自主题: Programming版 - typedef const char *month Table[3]
typedef是这样的:
你要typedef某一个类型,就写出如果要声明该类型的变量的
语句,“变量名”处放入你想要的新的类型名,然后前面加上
typedef
比如const chat *monthTable[3]声明了一个
名叫monthTable的一个长度为三的不可变字符指针数组,
那typedef const chat *monthTable[3]就
定义了一个名叫monthTable的类型为长度为三的不可变
字符指针数组
c**********e
发帖数: 2007
8
来自主题: JobHunting版 - C++ Q33: typedef (B4_20)
What is a benefit of using "typedef"?
a) It reduces the amount of memory required to create variables.
b) It creates more efficient code.
c) It increases performance by allocating more memory to create variables.
d) Using typedef can reduce the complexity of type definitions.
e) On most systems, using typedef for function definitions reduces link
times.
j***i
发帖数: 1278
9
来自主题: Programming版 - typedef 的一个问题
看c++ template数书上有段
Types that involve unnamed class types or unnamed enumeration types cannot b
e template type arguments (unnamed classes or enumerations that are given a
name through a typedef declaration are OK).
An example illustrates these two exceptions:
template class List {

};
typedef struct {
double x, y, z;
} Point;
typedef enum { red, green, blue } *ColorPtr;
int main()
{
struct Association
{
int* p;
int* q;
};
List e
s****n
发帖数: 700
10
来自主题: Linux版 - 问个C的typedef问题
【 以下文字转载自 Programming 讨论区 】
发信人: sallen (looking for job), 信区: Programming
标 题: 问个C的typedef问题
发信站: BBS 未名空间站 (Wed Jun 17 22:39:56 2009, 美东)
void *parray[10];
可以写成这样么?
typedef void* eleT;
eleT parray[10];
f********f
发帖数: 290
11
今天在看一个行业里的软件的文件头,
发现所有的定义都是:
struct Line_s
{
....
};
typedef Line_s Line_t;
为什么要变作_t的?这个有什么讲究么?除了以后改代码方便,比如
struct Line_New_s
{
....
};
typedef Line_s Line_t;
还有别的好处么?
thanks
l******e
发帖数: 13
12
To avoid confusion, you can also typedef it to itself:
typedef your_struct_type
{
...
}your_struct_type;
d****s
发帖数: 117
13
来自主题: Programming版 - about typedef
I see the following prototype:
typedef void (*fn) ( Session, Status);
what is the meaning of the keyword "typedef" here?
Thanks.
K****n
发帖数: 5970
14
来自主题: Programming版 - typedef
typedef 把一个struct变成 struct*, 没见过这种用法.
一般都是
typedef struct myStruct{
...;
} myStruct;吧
K****n
发帖数: 5970
15
来自主题: Programming版 - typedef

冲突的原因估计是:
rrc_List 本来是struct名,现在变成了rrc_List*
我试了下(先不typedef成指针),c++里声明struct可以用
rrc_List rrc_list;//绕过 struct rrc_List rrc_list;
现在typedef以后声明
rrc_List不知道是在说指针还是说他自己.
p****s
发帖数: 32405
16
来自主题: Programming版 - typedef struct的问题
问一下, 是不是名字其实也可以取重名?
like this:
typedef struct list {
int val;
struct list* next;
} list;
很多人喜欢写成typedef struct _A
{
...
} A; 只是为了自己看着清楚,但是在C标准里其实写成一样也没事?
p*****g
发帖数: 445
17
来自主题: Programming版 - typedef and operator new problem
我在code里面用了typedef定义以下
typedef state_t state_component[FC_MODES][TANK_LEVELS][BATT_LEVELS];
然后我用new新建两个指针
state_component* table1 = new state_component;
state_component* table2 = new state_component;
用vc++ 2005complie的时候报错
Error 30 error C2440: 'initializing' : cannot convert from 'state_t (*
)[256][256]' to 'state_component (*)'
但是当我把两个指针这样建立:
state_component* table1 = new state_component[1];
state_component* table2 = new state_component[1];
compile的时候就通过了。
望大牛出来传道授业解惑啊!
I*****y
发帖数: 602
18
来自主题: Programming版 - typedef 的一个问题
我的理解:
typedef enum { red, green, blue } *ColorPtr;
ColorPtr是个指针类型,指向无名的enum类型。
修改为:
typedef enum Color { red, green, blue } *ColorPtr;
可以通过编译。
而你定义的Point则是一个实实在在的无名的struct类型的别名。

b
a
d**********u
发帖数: 3371
19
来自主题: Programming版 - 请教一个C++ typedef的问题
这里面 在typedef定义了priority_queue的新类型之后 可以用
mypq_type fifth(mycomparison(true)); // greater-than comparison
来取代指点定义中的最后一个template 参数
但是假如要取代其中一个或者两个参数呢
试验了一下并不成功 比如
mypq_type six(deque, mycomparision(true));
谢谢
class mycomparison
{
bool reverse;
public:
mycomparison(const bool& revparam = false)
{
reverse = revparam;
}
bool operator() (const int& lhs, const int&rhs) const
{
if (reverse) return (lhs>rhs);
... 阅读全帖
t****t
发帖数: 6806
20
来自主题: Programming版 - 请教一个C++ typedef的问题
container type, as well as comparison functor, are types. you need to define
it in the typedef, e.g.
typedef priority_queue, mycomparison> mypq_type1;
c**********e
发帖数: 2007
21
来自主题: JobHunting版 - C++ Q56: map & typedef (C29)
typedef std::map MapType;
MapType theMap;
Referring to the code sample above, which one of the following blocks of
code displays the string contents of the entire map theMap?
a) MapType::iterator it = theMap.first();
while(it!= theMap.end()) std::cout << it;
b) MapType::iterator it = theMap.begin();
while(it!= theMap.end()) std::cout << theMap[it];
c) MapType::iterator it = theMap.begin();
while(it!= theMap.end()) std::cout << (*it++).second;
d) MapType::iterator it = theMap
f********r
发帖数: 50
22
来自主题: Programming版 - 关于typedef的一个问题
will typedef make new type?
or just an alias of the existing type.
Met it in an online test
can somebody explain?
n**d
发帖数: 9764
23
来自主题: Programming版 - typedef
Found this from a opensurce code, but it can not pass my compiler. How does
it work?
typedef struct rrc_List {
struct rrc_List *next;
int value;
} *rrc_List;
T*****9
发帖数: 2484
24
来自主题: Programming版 - typedef
typedef struct A{} *A?

does
j*****j
发帖数: 115
25
来自主题: Programming版 - typedef struct的问题
typedef struct
{
int val;
list* next;
} list;
为什么这段代码我不能编译通过?
c*****t
发帖数: 1879
26
来自主题: Programming版 - typedef struct的问题
Do something like:
typedef struct list_tag
{
int val;
struct list_tag* next;
} list;
w******g
发帖数: 67
27
来自主题: Programming版 - C++ question about template typedef
I have a question about template typedef. The question is that I want to use
the data structure like map>.
So I define the following:
#ifndef DATATEMPLATE_H_
#define DATATEMPLATE_H_
#include
#include
using namespace std;
/***************************************************************************
***********************************
* The following code define the type"MapOfVec"
* Map >
*
* Note: KeyType, ElementType are si
s****n
发帖数: 700
28
来自主题: Programming版 - 问个C的typedef问题
void *parray[10];
可以写成这样么?
typedef void* eleT;
eleT parray[10];
e****d
发帖数: 333
29
来自主题: Programming版 - typedef basic_string string;
切!
还小看人了?
等我学会了,看你还废话。
别的不说,你帮我找到 typedef basic_string string;并能解释给我,string
是怎么定义的,才能先证明你自己。
在 netghost (Up to Isomorphism) 的大作中提到: 】
m*****m
发帖数: 242
30
来自主题: Programming版 - typedef basic_string string;
get below by google, is it what you say?
Although we usually treat the C++ string as a class, this is really not the
case. The string type is a specialization of a more general constituent, the
basic_string< > template. Observe how string is declared in the Standard C+
+ header file:[38]
typedef basic_string string;
To understand the nature of the string class, look at the basic_string< >
template:
template,
class allocator = allocator
l*******r
发帖数: 511
31
来自主题: Programming版 - typedef const char *month Table[3]
所以我可以
monthtable t1={"January","Feb","Mar"};?
但是一般不是typedef A B;然后B就相当于A的type吗?

[]比*优先级更高,所以要这么看:
monthTable[3] => monthTable是一个长度为三的数组
*monthTable[3] => 这个数组的每个元素都是一个指针
const char *monthTable[3] => 这些指针指向不可变的字符
所以monthTable就是一个长度为三的不可变字符指针数组
t****t
发帖数: 6806
32
来自主题: Programming版 - typedef and operator new problem
to make the explanation shorter, let's see
typedef int A[2][3][4];
A* a1=new A;
preliminary: (new int) has type int*, and (new int[10]) also has type int*.
now, A has type int[2][3][4], which means A is "array 2 of (array 3 of array
4 of int)". new A has type "pointer to (array 3 of array 4 of int)".
but A* has type "pointer to array 2 of array 3 of array 4 of int". that's a
mismatch.
but new A[1] has type "pointer to array 2 of array 3 of array 4 of int".
that's a match.

(*
n********5
发帖数: 323
33
来自主题: Programming版 - C 中的typedef 一问
为什么下面不能编译通过???
typedef int int32;
int main(){
unsigned int32 j =10;
}
z***9
发帖数: 696
34
来自主题: Programming版 - C 中的typedef 一问
typedef unsigned int uint32;
int main(){
uint32 j =10;
}
g*********s
发帖数: 1782
35
来自主题: Programming版 - typedef的一个问题
my_class在某个头文件里定义,有一个method叫print()。
typedef my_class *my_class_p;
my_class *ptr1;
my_class_p ptr2;
ptr1 = new my_class;
ptr2 = ptr1;
在gdb里,做ptr1->print(),没问题。做ptr2->print(),返回错误信息。
但是如果做((my_class *)ptr2))->print(),结果也正确。
这是怎么回事呢?是不是和文件包含顺序有关?确实是一个比较复杂的系统里发现的问
题。
q*c
发帖数: 9453
36
来自主题: Programming版 - java没有typedef怎么办
typedef 是非常邪恶的东西
当年在 office 代码里面一个 int 能被定义成20 个不同的名字, 我干。
java 就是从过去野语言的血泪教训中过来的, 只是人类记忆不能遗传,
所以同样的错不断的有人当新发现来犯。。。

>()
b*******s
发帖数: 5216
37
来自主题: Programming版 - java没有typedef怎么办
typedef的初衷是提高移植性
现在当然是有更好的解决了,除非不得不用c
d**********u
发帖数: 3371
38
来自主题: Programming版 - 请教一个C++ typedef的问题
谢谢
那么关于这一行的用法
mypq_type fifth(mycomparison(true));
其作用只是给之前typedef中的mycomparision传递一个参数么?

define
c*******y
发帖数: 1630
39
来自主题: Programming版 - C++ 菜鸟问一个关于template 的问题。
good, works for both
/usr/include/c++/4.6.3/bits/stl_iterator_base_types.h
/// Partial specialization for pointer types.
template
struct iterator_traits<_Tp*>
{
typedef random_access_iterator_tag iterator_category;
typedef _Tp value_type;
typedef ptrdiff_t difference_type;
typedef _Tp* pointer;
typedef _Tp& reference;
};
/// Partial specialization fo... 阅读全帖
s******g
发帖数: 755
40
【 以下文字转载自 Apple 讨论区 】
发信人: faucetQ (fq), 信区: Apple
标 题: [Mac Dev]整了个ObjectiveC的笔记,看看气氛对得上不
发信站: BBS 未名空间站 (Mon Feb 2 21:38:18 2009), 转信
整了个类似ObjectiveC学习笔记的东西,发上来大伙看看有兴趣不。
修改了一点,增加了NSAutoreleasePool的内容。
增加了NSString内容。
===========俺系分隔线==================
本文假设读者有基本的C编程能力,如果有C++或者Java的背景会更容易理解但是不是必须。
ObjectiveC基本语法
消息
在objectiveC中,向一个对象发送一个消息的语法为
[ obj method:parameter];
类似的功能在C++中写作
obj->method(parameter);
在java中写作
obj.method(parameter);
在smalltalk中写作
obj method:parameter
显而易见objectiveC和smalltalk... 阅读全帖
f*****Q
发帖数: 1912
41
整了个类似ObjectiveC学习笔记的东西,发上来大伙看看有兴趣不。
修改了一点,增加了NSAutoreleasePool的内容。
增加了NSString内容。
===========俺系分隔线==================
本文假设读者有基本的C编程能力,如果有C++或者Java的背景会更容易理解但是不是必须。
ObjectiveC基本语法
消息
在objectiveC中,向一个对象发送一个消息的语法为
[ obj method:parameter];
类似的功能在C++中写作
obj->method(parameter);
在java中写作
obj.method(parameter);
在smalltalk中写作
obj method:parameter
显而易见objectiveC和smalltalk的语法基本是相同的。
当有两个或者两个以上的参数时,通常试用以的语法
[ obj method:parameter1 WithSecondParameter:parameter2];
定义一个类的代码放在一个.h文件中,下面是一个例子。
//macdevexample1.h
... 阅读全帖
d**********o
发帖数: 1321
42
来自主题: WebRadio版 - 潜水员冒泡兼征版友意见
hw3b c-.y file
上面这一楼贴了载止hw3b deadline时我match的结果(也就是老师可以以这些不match
的ERROR为借口不给后来我补上的成绩),但是因为当时我还是没有写完,后来感恩节
期间就接着又写了一些,而且hw5是based on hw3 & hw3b的基础上(当我hw5是based
on更好的hw3的结果时,我应该可以得更多的分吧)。
hw4因为写得比较顺利,就不曾保留任何交上去作业的output,没有什么一目了然的结
果是我可以贴在这里的。原本我是想要把自己最的一次作业hw5贴出来的,但那已经是
一个完整的compiler,而且以后我还需要用自己的course project来找工作,所以一定
就不贴最终结果了。那就贴一个hw3b的c-.y文件吧,它集中的hw1、hw2、hw3、 hw3b的
结果,是我自己hw3b *.y文件的最完整版本。这些作业里面也有很多机关一一人为增加
的难度,比如那六七个IO相关的function,不仅traverse tree、build syntax tree的
时候会成为一个考点(把它们作为一个node连在syntax... 阅读全帖
d**********o
发帖数: 1321
43
来自主题: WebRadio版 - 潜水员冒泡兼征版友意见
hw3b c-.y file
上面这一楼贴了载止hw3b deadline时我match的结果(也就是老师可以以这些不match
的ERROR为借口不给后来我补上的成绩),但是因为当时我还是没有写完,后来感恩节
期间就接着又写了一些,而且hw5是based on hw3 & hw3b的基础上(当我hw5是based
on更好的hw3的结果时,我应该可以得更多的分吧)。
hw4因为写得比较顺利,就不曾保留任何交上去作业的output,没有什么一目了然的结
果是我可以贴在这里的。原本我是想要把自己最的一次作业hw5贴出来的,但那已经是
一个完整的compiler,而且以后我还需要用自己的course project来找工作,所以一定
就不贴最终结果了。那就贴一个hw3b的c-.y文件吧,它集中的hw1、hw2、hw3、 hw3b的
结果,是我自己hw3b *.y文件的最完整版本。这些作业里面也有很多机关一一人为增加
的难度,比如那六七个IO相关的function,不仅traverse tree、build syntax tree的
时候会成为一个考点(把它们作为一个node连在syntax... 阅读全帖
u**********e
发帖数: 282
44
来自主题: Programming版 - 大家帮忙看看是什么问题
好久没用C++了,都忘光了。
大家帮忙解释一下下面ERROR是怎么回事
1.1 typedef std::wstring TLogicalIdentity;
1.1 typedef std::pair TLogicalKey;
1.1 typedef std::pair TExternalData;
1.1 typedef std::vector TEntryList;
1.1 typedef std::map TPerIdentityStatus;
1.1 typedef std::map
TIdentityStatus;
gcc3.4.5
In file included from ../../../DevTests/AssociativeCont
r****t
发帖数: 10904
45
非 template 情况似乎比较清楚了,class template 里面的 static data
member 的定义和初始化有没有啥龟腚?
举个例子:
template
class StackWithCapacity : public stack_adapter
{
public:
typedef typename stack_adapter< Container>::size_type size_type;
private:
static const size_type capacity = 5;
};
capacity 是个 static const member, 我就直接在 class body 里面初始化了,
据 c++ primer,class body 外面还必须 define without initializer (虽然我我不这么做也能编译并运行正常). 这样我就在外面加
template
StackWithCapacity... 阅读全帖
R*****i
发帖数: 2126
46
来自主题: JobHunting版 - 一道老题目, 求最快捷解法
这个题目建议用红黑树做可能最快捷有效。红黑树每一次插入,删除都是log(k),求平
均值非常简单,就是根部的那个节点。所以总的计算量是O(nlog(k))。
以下是c/c++代码(需要修改数组,以便一个一个输入)。
#include
#include
#include
#define INDENT_STEP 4
enum rbtree_node_color {RED, BLACK};
typedef struct rbtree_node_t {
int value;
struct rbtree_node_t* left;
struct rbtree_node_t* right;
struct rbtree_node_t* parent;
enum rbtree_node_color color;
} *rbtree_node;
typedef rbtree_node node;
typedef enum rbtree_node_color color;
typedef struct... 阅读全帖
d**********o
发帖数: 1321
47
来自主题: WebRadio版 - 潜水员冒泡兼征版友意见
第一个项目report
这时偶刚到CSAC工作不久,与小A同学还不熟,我用的还是latex。随着贴的作业越来越
多,应该是用有共同爱好的小伙伴更亲密些。这次贴latex,下次才再org-mode。
\documentclass[b5paper,11pt, abstraction, titlepage]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{CJKutf8}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{listings}
\usepackage{geometry}
\geometry{b5paper}
\usepackage{graphicx,floatrow}
\usepackage{graphicx,subfigure}
\newsavebox{\abstractbox}
\renewenvironment{abstract}
{\begin{lrbox}{0}\begin{minipage}{\t... 阅读全帖
d**********o
发帖数: 1321
48
来自主题: WebRadio版 - 潜水员冒泡兼征版友意见
第一个项目report
这时偶刚到CSAC工作不久,与小A同学还不熟,我用的还是latex。随着贴的作业越来越
多,应该是用有共同爱好的小伙伴更亲密些。这次贴latex,下次才再org-mode。
\documentclass[b5paper,11pt, abstraction, titlepage]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{CJKutf8}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{listings}
\usepackage{geometry}
\geometry{b5paper}
\usepackage{graphicx,floatrow}
\usepackage{graphicx,subfigure}
\newsavebox{\abstractbox}
\renewenvironment{abstract}
{\begin{lrbox}{0}\begin{minipage}{\t... 阅读全帖
p****o
发帖数: 46
49
来自主题: JobHunting版 - 狗家面经
cool. 什么编程语言?第二题, 上个c++:
using namespace std;
list intersect(list intList1, list intList2){
list::const_iterator it1 = intList1.begin();
list::const_iterator it2 = intList2.begin();
list intList3;
while((it1 != intList1.end()) && (it2 != intList2.end())) {
if (*it1 == *it2) {
intList3.push_back(*it1);
++it1;
++it2;
} else if (*it1 < *it2) {
++it1;
... 阅读全帖

发帖数: 1
50
来自主题: Joke版 - 求助术版 - 加,减,乘,除
http://rosettacode.org/wiki/24_game/Solve#C
改一下就行了。这是输入4个的,可以改成输入3个的。
6 17 3 7: No solution
……
#include
#include
#include
#define n_cards 4
#define solve_goal 29
#define max_digit 9
typedef struct { int num, denom; } frac_t, *frac;
typedef enum { C_NUM = 0, C_ADD, C_SUB, C_MUL, C_DIV } op_type;
typedef struct expr_t *expr;
typedef struct expr_t {
op_type op;
expr left, right;
int value;
} expr_t;
void show_expr(expr e, op_type prec, int is_r... 阅读全帖
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)