由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 请教个C++的问题
相关主题
C++ Function Pointer Array 的问题c++ 里用到pointer 的地方我们尽可能用smart pointer吗?
[合集] can one type cast reference in C++不如各位高手挑个专题讲讲C++11吧
Why do I need to use "plain" pointer?Go adopts JavaScript’s idea of semicolon insertion
is smart_ptr really that good?当某个函数被调用的时候,需要定义一个宏
pointer overflow一个小问题
C++ Q05: pointer to constant variable[合集] what's the trick of passing pointers
C++ Q93 - Q95 (转载)Pointer to iterator?
int F::*x = &F::x是什么意思?为什么virtual memory的0地址不能给用户程序访问
相关话题的讨论汇总
话题: point话题: line话题: class话题: c++话题: std
进入Programming版参与讨论
1 (共1页)
x******a
发帖数: 6336
1
我先定义一个
class Point{
...
};
然后要定义一个class Line,下面两个定义更prefer哪一个?
1. class Line{
std::vector vecA;
...
};
2. class Line{
A* a;
size_t n;
...
}
谢谢
p***o
发帖数: 1252
2
1

【在 x******a 的大作中提到】
: 我先定义一个
: class Point{
: ...
: };
: 然后要定义一个class Line,下面两个定义更prefer哪一个?
: 1. class Line{
: std::vector vecA;
: ...
: };
: 2. class Line{

a9
发帖数: 21638
3
难道不应该是
line{
point start;
point end;吗?
}

【在 x******a 的大作中提到】
: 我先定义一个
: class Point{
: ...
: };
: 然后要定义一个class Line,下面两个定义更prefer哪一个?
: 1. class Line{
: std::vector vecA;
: ...
: };
: 2. class Line{

x******a
发帖数: 6336
4
谢谢,point不是pointer。
修改了。

【在 a9 的大作中提到】
: 难道不应该是
: line{
: point start;
: point end;吗?
: }

x******a
发帖数: 6336
5
多谢,请问一下为什么1好一些,
我能想到的是不用做resource management。

【在 p***o 的大作中提到】
: 1
m*******l
发帖数: 12782
6
depends

【在 x******a 的大作中提到】
: 我先定义一个
: class Point{
: ...
: };
: 然后要定义一个class Line,下面两个定义更prefer哪一个?
: 1. class Line{
: std::vector vecA;
: ...
: };
: 2. class Line{

j******t
发帖数: 788
7
because opt 1 reduce your coding works

【在 x******a 的大作中提到】
: 多谢,请问一下为什么1好一些,
: 我能想到的是不用做resource management。

d******3
发帖数: 70
8
两个都有隐患。
1会reallocate,造成浪费。
2的问题就更多了。difficult to manage,not safe,etc
比较好的方法是:
std::vector vecp;
想更安全点的话这样:
std::vector< unique_ptr > vecp;
或:
std::vector< shared_ptr > vecp;

【在 x******a 的大作中提到】
: 我先定义一个
: class Point{
: ...
: };
: 然后要定义一个class Line,下面两个定义更prefer哪一个?
: 1. class Line{
: std::vector vecA;
: ...
: };
: 2. class Line{

t****t
发帖数: 6806
9
除非你的Point非常大, 否则没必要用指针, 完全是不必要的开销.

【在 d******3 的大作中提到】
: 两个都有隐患。
: 1会reallocate,造成浪费。
: 2的问题就更多了。difficult to manage,not safe,etc
: 比较好的方法是:
: std::vector vecp;
: 想更安全点的话这样:
: std::vector< unique_ptr > vecp;
: 或:
: std::vector< shared_ptr > vecp;

1 (共1页)
进入Programming版参与讨论
相关主题
为什么virtual memory的0地址不能给用户程序访问pointer overflow
菜鸟请教smart pointerC++ Q05: pointer to constant variable
自学C语言-书和online resources (转载)C++ Q93 - Q95 (转载)
弱问c++ iterator 和 pointer区别int F::*x = &F::x是什么意思?
C++ Function Pointer Array 的问题c++ 里用到pointer 的地方我们尽可能用smart pointer吗?
[合集] can one type cast reference in C++不如各位高手挑个专题讲讲C++11吧
Why do I need to use "plain" pointer?Go adopts JavaScript’s idea of semicolon insertion
is smart_ptr really that good?当某个函数被调用的时候,需要定义一个宏
相关话题的讨论汇总
话题: point话题: line话题: class话题: c++话题: std