English 中文(简体)
如何在C++另一构造者中初步确定物体[封闭]
原标题:How to initialize an object inside another constructor in C++ [closed]

这个问题似乎并不涉及在help Center中界定的范围之内的方案规划。

Closed 3 hours ago.

The community is reviewing whether to reopen this question as of 2 hours ago.

Im公司正在建造一个班级,在图书馆一米上增加更方便的功能,与LCD显示器相连接。 然而,我仍需要在本班内使用图书馆,这要求我从该班子中储存一个物体,作为我的班子成员。 我发现一篇文章显示,该物体的初衷是:

class Display {
    private:
        LibraryClass myObject;

    public:
        Display(int inputPin) : myObject(inputPin){}
}

然而,我随后试图创建<条码>。 反对:

Display myObject(myInputPin);

然而,编辑们在我的“目标列为预期的初始器。 为了解决这一问题,我把论点清单增列到<编码>。 显示如下:

Display(myInputPin) myObject(myInputPin);

编辑员然后在我的办公室目标之前再犯另一个错误,即<代码>。

Display(myInputPin), myObject(myInputPin);

编辑人员不再出现任何错误,Im能够使用myObject。 我的法典其余部分。 然而,我仍然对这一最后的法典线感到不安:它是否真的做我所期望和创建的<条码>米奥目标。 您在使用初步清单时是否应当制造物体?

问题回答

你对<代码>显示<>/代码”的定义现在正确。 为了制造一个类型的<代码>Display,你需要写:

Display myDisplay(myInputPin);




相关问题
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?

热门标签