本文介绍了在C ++我不能抓住指针和类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚从大学毕业,现在已经在C ++中工作了一段时间。我理解C ++的所有基础知识并使用它们,但我很难掌握更高级的主题,如指针和类。我读过一些书和教程,我理解他们的例子,但是当我看一些高级的现实生活中的例子,我不能想出来。这是杀了我,因为我觉得它让我从我的C ++编程提高到一个新的水平。有没有人有这个问题?如果是,你是如何突破呢?
有人知道任何书或教程,真正描述指针和类的概念吗?
或者也许一些示例代码与良好的描述性评论使用高级指针和类技术?

I'm fresh out of college and have been working in C++ for some time now. I understand all the basics of C++ and use them, but I'm having a hard time grasping more advanced topics like pointers and classes. I've read some books and tutorials and I understand the examples in them, but then when I look at some advanced real life examples I cannot figure them out. This is killing me because I feel like its keeping me from bring my C++ programming to the next level. Did anybody else have this problem? If so, how did you break through it?Does anyone know of any books or tutorials that really describe pointers and class concepts well?or maybe some example code with good descriptive comments using advanced pointers and class techniques?any help would be greatly appreciated.

推荐答案

指针和类在C ++中不是真正的高级主题。它们是非常根本的。

Pointers and classes aren't really advanced topics in C++. They are pretty fundamental.

对我来说,当我开始用箭头绘制框时,指针会凝固。为int绘制一个框。和int *现在是一个单独的框,箭头指向int框。

For me, pointers solidified when I started drawing boxes with arrows. Draw a box for an int. And int* is now a separate box with an arrow pointing to the int box.

因此:

int foo = 3;           // integer
int* bar = &foo;       // assigns the address of foo to my pointer bar

选择要么查看框内的地址。 (这是foo的内存地址)。或者我可以操纵我有一个地址。那个操作意味着我跟着那个箭头到整数(foo)。

With my pointer's box (bar) I have the choice of either looking at the address inside the box. (Which is the memory address of foo). Or I can manipulate whatever I have an address to. That manipulation means I'm following that arrow to the integer (foo).

*bar = 5;  // asterix means "dereference" (follow the arrow), foo is now 5
bar = 0;   // I just changed the address that bar points to

类是另一个主题。有一些关于面向对象设计的书,但我不知道为我的头顶的初学者好。你可能有一本介绍Java书的运气。

Classes are another topic entirely. There's some books on object oriented design, but I don't know good ones for beginners of the top of my head. You might have luck with an intro Java book.

这篇关于在C ++我不能抓住指针和类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 13:09