| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5551 人关注过本帖
标题:C++ forums 的鬼佬对话 Pointers and functions
只看楼主 加入收藏
点线面
Rank: 8Rank: 8
来 自:NO.-1
等 级:蝙蝠侠
帖 子:525
专家分:980
注 册:2011-1-3
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:5 
C++ forums 的鬼佬对话 Pointers and functions
Okay so I've been wrestling with this for two days for a total of well over 20 hours. I've read through
 好的  我为这个耗二日多出20小时.
the tutorial on this site and five other sites, watched a YouTube vid about it and read my book.
我通过这个网站和四个网站去理解.上YouTube看这个,而且还看书
A few times over. I normally wouldn't ask, but I have this week to learn about pointers and classes
时间过去。我不说什么,但是我在周未学习指针和类,更多关注类与继承.
and more about classes and inheritance. That's about 150 pages in my book. I am getting a little stressed
系我书本150页。我依然感得不知所措
 over this.

I've been sitting with this up for 20 minutes and I still don't know how to concretize what I am asking
我一直坐到20分钟,我仍然不知道怎样表达
 for into a question. Any example involving a function with pointers (including one as an argument for
一些例子包括函数里的指针和我希望一步步做什么整合到字符类型的变值
that function) and char type variables with a nice step by step walkthrough on what's what will do... I hope.

For starters, take a look at this POC-code here.

 #include <iostream>

void converter(const char *aString)
{
  const char *charPointer = "Hello!";
  charPointer = aString;
}
int main()
{
  const char *myString = "Good-bye.";
  converter(myString);
  std::cout << myString;
}
 



I want myString to print out "Hello!" but it prints out "Good-
我想这行输出"Hello!" ,但是它输出"Good-bye.";
bye.", so obviously my function isn't doing what I want it to do. Why? And any suggestions on how to make
         不按我的意愿去做,为什么?有什么建意按我的思法去做
 it so?
 
firedraco (3536)     Jan 5, 2011 at 5:36am
Your converter function is not actually changing the pointer you are passing.
你的转换函数指针其实并没有改变你过去了。

 void converter(const char *aString)
{
  const char *charPointer = "Hello!"; //make a local variable
  charPointer = aString; //make it point to whatever aString is pointing at
}
 



Anyway, you can't actually change myString since it is a const char*. That means it is a pointer to some
 constant (unchangeable) data, so if you try to modify it you will get an error.
不管怎样,你不能改变myString由于它是一个常量字符*。
,这意味着它是一个指向一些常数(不变的)数据,因此,如果你想要修改它,你将会得到一个错误。
Have you looked at the tutorial for pointers on this site? Try that if you haven't already.
如果你没有在网上看关于指针的教程?那么你尝试

PS:翻译还是一踏糊涂
搜索更多相关主题的帖子: YouTube 20小时 about book 时间 
2011-01-05 13:47
alwaysfocus
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:25
专家分:138
注 册:2010-12-15
收藏
得分:20 
Okay so I've been wrestling with this for two days for a total of well over 20 hours.
应该是两天内一共花了20小时,不是两天零20小时。
Your converter function is not actually changing the pointer you are passing.
实际上,converter()函数并没有改变你所传递的指针。
2011-01-06 13:53
点线面
Rank: 8Rank: 8
来 自:NO.-1
等 级:蝙蝠侠
帖 子:525
专家分:980
注 册:2011-1-3
收藏
得分:0 
Your converter function is not actually changing the pointer you are passing.

PS:顺便问一下 。。。actually changing the pointer you are passing.语法结构怎样,好像缺省了什么。


小代码,大智慧
2011-01-06 14:20
alwaysfocus
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:25
专家分:138
注 册:2010-12-15
收藏
得分:0 
Your converter function is not (actually) changing the pointer (that) you are passing.
      主语                         谓语                 宾语            定语从句(这里省略了引导词)
2011-01-06 14:26
点线面
Rank: 8Rank: 8
来 自:NO.-1
等 级:蝙蝠侠
帖 子:525
专家分:980
注 册:2011-1-3
收藏
得分:0 

定语从句
  定语从句是由关系代词或关系副词引导的从句,其作用是作定语修饰主句的某个名词性成分,相当于形容词,所以又称为形容词性从句,一般紧跟在它所修饰的先行词后面。在复合句中,修饰某一名词或代词叫做定语从句。
关系词
  引导定语从句的关联词称为关系词,关系词有关系代词和关系副词。关系代词有that, which, who, whom, whose, as等,绝对没有what;关系副词有where, when, why等。关系词常有3个作用:   ①连接作用,引导定语从句。   ②代替主句中的先行词,甚至可能是主句中的一部分或者整个主句。   ③在定语从句中充当一句子成分。

which, that
  它们所代替的先行词是事物的名词或代词,在从句中可作主语、宾语等,作宾语时可以省略,例如:   (1) A prosperity which / that had never been seen before appears in the countryside. 农村出现了前所未有的繁荣。(which / that在句中作主语)   (2) The package (which / that) you are carrying is about to come unwrapped. 你拿那个包裹快要散开了。(which / that在句中作宾语)

小代码,大智慧
2011-01-06 14:37
Alar30
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:10
帖 子:988
专家分:1627
注 册:2009-9-8
收藏
得分:0 
呵呵
好多年没有整E文了
2016-01-29 08:50
快速回复:C++ forums 的鬼佬对话 Pointers and functions
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022240 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved