函数没有定义的问题

Sigger 2008-12-15 04:25:54
.....
void CKDtreeView::Generate_Random_Point(int* p , int sd)
{
for(int k=0; k<sd; k++)
p[k] = rand() % RMAX ;
}
KDTree<int> Tree;
void GenerateRandomTree(int nNodes)//由随机点构建随机树
{
int p [SD]; // random point
for(int n=0; n<nNodes; n++)
{
Generate_Random_Point(p, SD);
Tree.add(p);
}
}
........
上述代码CKDtreeView.cpp中一段,但是编译通不过,说:1>c:\documents and settings\scan\desktop\kdtree\kdtree\kdtreeview.cpp(207) : error C3861: 'Generate_Random_Point': identifier not found!
不知道是怎么回事,请大家帮个忙看看!谢谢
...全文
155 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Sigger 2008-12-15
  • 打赏
  • 举报
回复
呵呵 我使用了成员函数要通过类对象调用的方法,但是有这样的错误:'CKDtreeView::CKDtreeView' : cannot access protected member declared in class 'CKDtreeView',后来我用CKDtreeView* obj;obj->Generate_Random_Point(p,SD);才没有错误提示!
wap21 2008-12-15
  • 打赏
  • 举报
回复
帮顶
pony_ml 2008-12-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 hai040 的回复:]
CKDtreeView obj;
obj.Generate_Random_Point(p, SD);
成员函数要通过类对象调用
[/Quote]
y
keven1868 2008-12-15
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 nullah 的回复:]
C/C++ code
for(int n=0; n <nNodes; n++)
{
yourObject.Generate_Random_Point(p, SD); //类的成员函数通过对象调用
Tree.add(p);
}
[/Quote]

y
Sigger 2008-12-15
  • 打赏
  • 举报
回复
头文件中定义了Generate_Random_Point(),但void GenerateRandomTree()没有定义!
按照类的成员函数通过调用的方法,提示错误: 'CKDtreeView::CKDtreeView' : cannot access protected member declared in class 'CKDtreeView'。
下面是.h文件代码:
// KDtreeView.h : interface of the CKDtreeView class
//
///////////////////////////////////////////////////////////
//User add
#include <Inventor/Win/SoWin.h>
#include <Inventor/Win/viewers/SoWinExaminerViewer.h>

/*#include <Inventor/Win/SoWin.h>
#include<Inventor/Win/viewers/SoWinExaminerViewer.h>
#include <Inventor\SoDB.h>
#include <Inventor\SoInput.h>
#include <Inventor\Win\SoWin.h>
#include <Inventor\Win\SoWinRenderArea.h>
#include <Inventor\nodes\SoBlinker.h>
#include <Inventor\nodes\SoDirectionalLight.h>
#include <Inventor\nodes\SoMaterial.h>
#include <Inventor\nodes\SoOrthographicCamera.h>
#include <Inventor\nodes\SoPerspectiveCamera.h>
#include <Inventor\nodes\SoSeparator.h>
#include <Inventor\nodes\SoTransform.h>*/
//////////////////////////////////////////////////////////

#pragma once


class CKDtreeView : public CView
{
protected: // create from serialization only
CKDtreeView();
DECLARE_DYNCREATE(CKDtreeView)

// Attributes
public:
CKDtreeDoc* GetDocument() const;

CClientDC* pDC;//user

// Operations
public:
////////////////////////////////////
//user add
public:
SoWinExaminerViewer * viewer;
///////////////////////////////////

// Overrides
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);

// Implementation
public:
virtual ~CKDtreeView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
public:
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
public:
void Generate_Random_Point(int* p , int sd);
public:
afx_msg void OnFileNew();
public:
afx_msg void OnFileSave();
};

#ifndef _DEBUG // debug version in KDtreeView.cpp
inline CKDtreeDoc* CKDtreeView::GetDocument() const
{ return reinterpret_cast<CKDtreeDoc*>(m_pDocument); }
#endif
nullah 2008-12-15
  • 打赏
  • 举报
回复

for(int n=0; n <nNodes; n++)
{
yourObject.Generate_Random_Point(p, SD); //类的成员函数通过对象调用
Tree.add(p);
}
xtting_8984313 2008-12-15
  • 打赏
  • 举报
回复
.h文件贴出来啊
kier2 2008-12-15
  • 打赏
  • 举报
回复
你CKDtreeView的头文件里声明了这个函数没?
hai040 2008-12-15
  • 打赏
  • 举报
回复
CKDtreeView obj;
obj.Generate_Random_Point(p, SD);
成员函数要通过类对象调用

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧