English 中文(简体)
涉及以下方面的前期声明:
原标题:Forward declarations that involve std::vector, etc

我已经用了许多先期声明;这些声明有助于避免许多<条码>,即:pinclude,改进汇编时间,而不是什么。 但是,如果想向标准图书馆宣布一个班子的话?

// Prototype of my function - i don t want to include <vector> to declare it!
int DoStuff(const std::vector<int>& thingies);

我听说,禁止/不可能提前申报<代码>std:vector。 如今,

<>斯特凡>

class VectorOfNumbers; // this class acts like std::vector<int>
int DoStuff(const VectorOfNumbers& thingies);

<>strong>stuff.cpp

// Implementation, in some other file
#include <vector>
class VectorOfNumbers: public std::vector<int>
{
    // Define the constructors - annoying in C++03, easy in C++11
};

int DoStuff(const VectorOfNumbers& thingies)
{
    ...
}

现在,如果在我整个项目的所有情况下都使用<条码>。

这种技术是否有重大缺点? 能够提前申报<条码>查询/代码>的好处是否大于?

最佳回答

我为什么不这样做:

const std::vector<int>& a = a_3rd_party_lib::get_data(); // this type is out of your control
DoStuff(a); // you cannot pass it to this function! 
问题回答

If you ever delete a VectorOfNumbers as a std::vector<int> (and since you used public inheritance this conversion is implicit) you ve entered the realm of undefined behavior. This is probably more likely to accidentally happen than one might suspect.

我从未在需要时看到过从仅包括<代码> vector<>/code”在内的大量汇编减速,但如果你真的想要孤立其中的话,则使用用户的APIC界面,而该接口对集装箱的基本类型(vector)和皮条(vector<>/code>)都知道。

页: 1 <代码><vector>的头盔将建立起来,以防止出现多重包容,因此,你只把需要列入任何地方。

这对一个班子的接口来说是好的,但不是执行。 1. 如果您的班级有<条码>,即。 页: 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?

热门标签