因此,我已在我的班头上宣布了病媒:
...
private:
vector<Instruction> instructions;
...
然后,在施工者执行时,我试图把它当作一开始:
instructions = new vector<Instruction>();
缩略语
我基本上试图使这一类人的行为像我期望的那样,在java,这一类人保留这一病媒。 因此,我想用<条码>新条码>来积极分配这一条,以确保它不会被丢掉。 非常感谢任何帮助。
因此,我已在我的班头上宣布了病媒:
...
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++中不使用<条码>新代码>,除非你知道你正在做什么。 (瓦希,目前不是)
而是使用自动物体。 您已经将<条形码>作为自动物体。 你们需要把它当作是:
class wrgxl {
public:
wrgxl()
: instructions() // this initializes the vector using its default constructor
{
// nothing needed here
}
...
private:
vector<Instruction> instructions;
...
};
施工人初始化名单上的<代码>instructions的初始化是任择的,但如果你只想说违约施工人的话。 因此,在这种情况下,这足以:
wrgxl()
{
}
If you wanted to dynamically allocate a vector, you would need to make instructions
a pointer to a vector. But this rarely ever make sense, since the vector already allocates its data dynamically, but wraps this, so you do not have to deal with the ugly details resulting from this.
One of those details is that, if you have a dynamically allocated object in a class, you will then have to worry about destruction, copy construction, and copy assignment for that class.
正如Kerrek已经指出的,为了适当学习C++,你需要<><>>一个好的C++书,<<><<> >.Make Youcr<>:>>。
我认为你把C++与C# syntax混为一谈。
首先,与许多语言不同的是,分配用于 st的变数(如你)是通过叫作违约建筑商而开始的,因此,我怀疑你做的事情是不必要的。
第二,为了做你试图做的事情,你利用以下辛迪加:
instructions = vector<Instruction>();
然而,正如我所说的那样,这很可能是多余的(而且对非优化的汇编者来说是浪费的,因为它既可以称作构造者,也可以指转让经营人)。 单方回答中找到了更好的办法。
第三,与C#不同的是,new
的操作者分配了有关蒸气的记忆,并向新分配的数据投了一名点子。 页: 1
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 ...
I have been searching for sample code creating iterator for my own container, but I haven t really found a good example. I know this been asked before (Creating my own Iterators) but didn t see any ...
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 ...
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?
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->...
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, ...
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 ...
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?