English 中文(简体)
为什么这一病媒分配没有得到接受?
原标题:Why is this allocation of a vector not accepted?

因此,我已在我的班头上宣布了病媒:

 ...
 private:
    vector<Instruction> instructions;
 ...

然后,在施工者执行时,我试图把它当作一开始:

 instructions = new vector<Instruction>();

缩略语

我基本上试图使这一类人的行为像我期望的那样,在java,这一类人保留这一病媒。 因此,我想用<条码>新来积极分配这一条,以确保它不会被丢掉。 非常感谢任何帮助。

最佳回答

页: 1

vector<Instruction> instructions;

你们已经对贵阶层用户使用的任何记忆模式发出指示。

class YourClass
{
vector<Instruction> instructions;
};

...
int main()
{
   YourClass class1; // stack
   std::unique_ptr<YourClass> class2(new YourClass); // heap
...
}
问题回答

为了做您重新尝试做以下工作:instructions = 新的矢量设计;Instruction>行完全没有必要。 简单删除。 矢量一旦成形,就会自动形成违约。

另一种办法是将<条码>指示/编码>变成点,但似乎没有理由在此这样做。

在您的班次中,您宣布了<代码>std:vector<Instruction>new path<Instruction> 返回您std:vector< 教学法;∗

<代码>新的收益指点人,因此,您的类型不匹配。

The real issue is the fact that you are doing it at all. Do you have a good reason for dynamically allocating that vector? I doubt it, just omit that entirely as it will be allocated along with instances of your type.

You have a member value but you try to initialize it from a vector<Instruction>*. Initialize it from vector<Instruction> or change the declaration to a pointer. If you go down the second route, you need to observe the rule of three.

您也不妨从上获得一份体面的C++书。 * E/CN.6/2009/1。

此外,我认为,你有一张<密码>,使用名称空间;在座标上是坏的。

我认为你把C++与C# syntax混为一谈。

首先,与许多语言不同的是,分配用于 st的变数(如你)是通过叫作违约建筑商而开始的,因此,我怀疑你做的事情是不必要的。

第二,为了做你试图做的事情,你利用以下辛迪加:

instructions = vector<Instruction>();

然而,正如我所说的那样,这很可能是多余的(而且对非优化的汇编者来说是浪费的,因为它既可以称作构造者,也可以指转让经营人)。 单方回答中找到了更好的办法。

第三,与C#不同的是,new的操作者分配了有关蒸气的记忆,并向新分配的数据投了一名点子。 页: 1





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签