English 中文(简体)
从头文件获取数据到源文件中的非成员函数
原标题:Get data from header file into non-member function in source file

我有像BigArr这样的数据,呃,... 在信头中宣布:

class TableView:public QWidget 
{
  Q_OBJECT

  public:TableView (QWidget * parent = 0);

  std::vector < TXdata >  BigArr;

  std::vector < float >  arr;
  std::vector < float >  arr2;
  std::vector < int >  arrlocKtab;
  std::vector < int >  arrlocKrow;

在源文件中,我有一些功能,我从别处复制/改写,例如:

static void
 multiply (float q[4], float value)
{
  q[0] *= value;
  q[1] *= value;
  q[2] *= value;
  q[3] *= value;
}

和一些其他功能,我做了,例如:

 void
 TableView::ShowContextMenu (const QPoint & pos)    // this is a slot
 {

如何从信头文件中获取声明以在副本/粘贴功能内工作。 例如 :

  static void
     multiply (float q[4], float value)
    {

  arr[0]= something...

将 c/ p 函数重新命名为无效表V:: 函数并将其添加到信头文件中的函数列表中, 我得到了一些错误的结果。 可能与静态无效( amp); 静态内线无效( Ty) 有关...

最佳回答

您必须将乘数函数定义为表View 类的一部分,定义如下:

class TableView:public QWidget 
{
    ...
    void multiply(float q[4], float value);
    ...
};

然后在源文件中定义它像这样 :

void TableView::multiply(float q[4], float value)
{
    ...
    arr[0] = something;
    ...
}

或者,如果您不能/不想使它成为表查看的成员,您可以通过一个“表查看”实例进行乘数()。如果您决定通过“表查看”实例到该函数,那么您将不得不考虑如何访问该类成员,或者通过设置“获得者”函数,或者将其公诸于众。获得者“获得者”函数是一个更清洁的解决方案。

无论哪种方式都行, 但如果你决定让所有成员都发挥功能, 考虑设计, 确保班级不会膨胀, 被称为低凝聚力: en.wikipedia.org/wiki/ Single_ responsible_ responsibility_ procility

问题回答

暂无回答




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

热门标签