首页 \ 问答 \ 嵌套类访问封闭类的私有数据成员(Nested class' access to enclosing class' private data members)

嵌套类访问封闭类的私有数据成员(Nested class' access to enclosing class' private data members)

我在实现一个嵌套类的时候遇到了麻烦,它的构造函数是用一些封闭类的私有数据成员初始化的。

例:

Header File:
class Enclosing {
   //...Public members
   //...Private members
   int x, int y
   class Inner; // Declaration for nested class
};

Impl. File:
// Stuff...
class Enclosing::Inner {
    explicit Inner() : foo(x), bar(y) // foo and bar are data members of Inner
    //...
};

我得到了invalid use of non-static data member错误的invalid use of non-static data member 。 当涉及到嵌套类访问其封闭类的成员时,是否有某些我错过了?


I'm having trouble implementing a nested class who's constructor is initialized with some of the enclosing class' private data members.

Example:

Header File:
class Enclosing {
   //...Public members
   //...Private members
   int x, int y
   class Inner; // Declaration for nested class
};

Impl. File:
// Stuff...
class Enclosing::Inner {
    explicit Inner() : foo(x), bar(y) // foo and bar are data members of Inner
    //...
};

I get an invalid use of non-static data member error. Is there something I'm missing when it comes to nested class access to its enclosing class' members?


原文:https://stackoverflow.com/questions/1604853
更新时间:2021-05-14 22:05

最满意答案

那么,它主要取决于你的特定实现和数据集。

一棵平衡不良的树意味着你必须搜索比你需要的更多的数据。 确保你的树木结构健全。

这也可能取决于你如何找到k个邻居。 如果你的算法搜索最近邻居的树并存储它,然后搜索第二个最近的邻居并存储它等,那么你不会非常有效地进行搜索。 相反,当您找到更近的遍历树的列表时,请将列表中的k个最近邻居列表和碰撞点列表从列表中移出。 这样你搜索一次,而不是k次。

无论哪种方式,这听起来像你正在做这个课程。 尝试与你的教授,助教或同学交谈,看看你的结果是否典型。


Well, it primarily depends on your particular implementation and data set.

A poorly balanced tree will mean you have to search way more data than you need to. Make sure that your tree construction is sane.

It could also depend on how you find the k neighbors. If your algorithm searches the tree for the closest neighbor and stores it, then searches for the second closest and stores it etc, then you're not doing the search very efficiently. Instead keep a running list of the k nearest neighbors and bump points out of the list as you find closer ones traversing the tree. This way you search once, instead of k times.

Either way, it sounds like you're doing this for a course. Try talking to your professor, TAs, or classmates to see if your results are typical.

相关问答

更多
  • 那么,它主要取决于你的特定实现和数据集。 一棵平衡不良的树意味着你必须搜索比你需要的更多的数据。 确保你的树木结构健全。 这也可能取决于你如何找到k个邻居。 如果你的算法搜索最近邻居的树并存储它,然后搜索第二个最近的邻居并存储它等,那么你不会非常有效地进行搜索。 相反,当您找到更近的遍历树的列表时,请将列表中的k个最近邻居列表和碰撞点列表从列表中移出。 这样你搜索一次,而不是k次。 无论哪种方式,这听起来像你正在做这个课程。 尝试与你的教授,助教或同学交谈,看看你的结果是否典型。 Well, it prim ...
  • 如果从内部查询中删除TOP (1) WITH TIES ,并将外部查询设置为返回前k行,会发生什么情况? 我也很想知道这个修正案是否有帮助。 它应该比使用TOP更高效: DECLARE @start FLOAT = 1000 ,@k INT = 20 ,@p FLOAT = 2; WITH NearestPoints AS ( SELECT * ,T.g.STDistance(@x) AS dist ,ROW_NUM ...
  • 省略进口...我没有你的数据,所以我必须伪造一些... In [40]: x = np.random.random(100) In [41]: y = np.random.random(100) In [42]: z = np.random.random(100) In [43]: p = np.random.random(3) In [44]: p Out[44]: array([ 0.60515083, 0.39263392, 0.36129813]) 即三个坐标阵列和我将 ...
  • k是数据的维数 ,而n是数据集中的点数 。 因此,如果您的数据集包含1000万个点,并且每个点有3个维度,则k为3, n为1000万。 kd树不适合在高维度上找到最近邻居的原因与所谓的维度诅咒有关 。 kd树反复使用沿着单个维度的分割,但是当处理高维数据时,在一个维度上知道关于(欧几里得)距离的某些东西对于整个空间中的距离几乎没有说明。 想要超过2 k的数据集的原因非常直观:我们将数据集沿着每个维度分成两半大小相等的数据集。 如果我们的数据点少于2 k ,过了一段时间就没有更多的数据需要拆分了! 例如,如果 ...
  • 使用pdist2 : A = rand(20,5); %// This is your 11795 x 88 B = A([1, 12, 4, 8], :); %// This is your n-by-88 subset, i.e. n=4 in this case n = size(B,1); D = pdist2(A,B); [~, ind] = sort(D); kneighbours = ind(2:2+k, :); 现在你可以使用kneighbours来索引A的 ...
  • 我们在之前的项目中使用了一个宝石: https://rubygems.org/gems/kdtree 它还有一个线程安全的分支: https://rubygems.org/gems/tupalo-kdtree 也许在实现自己之前先看一下。 There's a gem that we used in a previous project: https://rubygems.org/gems/kdtree There's also a thread-safe fork of it: https://rubyge ...
  • 我将建议使用具有KNeighborsClassifier的python库sklearn ,一旦适合,您可以检索您正在寻找的最近邻居: 试试这个: # Import from sklearn.neighbors import KNeighborsClassifier # Instanciate your classifier neigh = KNeighborsClassifier(n_neighbors=4) #k=4 or whatever you want # Fit your classifier ...
  • 使用LineCollection一次绘制所有边,而不是逐个绘制它们: import numpy as np from scipy.spatial.distance import pdist, squareform from matplotlib import pyplot as plt from matplotlib.collections import LineCollection N = 250 X = np.random.rand(250,2) k = 4 # matrix of pairwise ...
  • 您只需在绘制线条之前对x值进行排序。 plot(x,y) ORD = order(grid2$x) lines(grid2$x[ORD],knn10$pred[ORD]) You just need to sort the x values before plotting the lines. plot(x,y) ORD = order(grid2$x) lines(grid2$x[ORD],knn10$pred[ORD])
  • 你在这里有一个典型的模型选择问题。 你想要的是选择k ,它可以为你的数据提供最低的整体错误。 较大的k值更好地概括,较小的值可能倾向于过度拟合。 因此,交叉验证是选择此参数的好方法,我发现了这篇文章 ,这似乎是一种合理的方法。 What you have here is a typical model selection problem. What you want is to pick the k that gives you the lowest overall error on your data. ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)