PDA

View Full Version : استفاده از Vector



devilishruby
جمعه 25 بهمن 1387, 22:15 عصر
مشکلم توی کد زیر کجاست که با ارور زیر برخورد می کنم؟



namespace VL{
class Sift
{
struct Keypoint
{
int o ; ///< Keypoint octave index
int ix ; ///< Keypoint integer X coordinate (unnormalized)
int iy ; ///< Keypoint integer Y coordinate (unnormalized)
int is ; ///< Keypoint integer scale indiex
float_t x ; ///< Keypoint fractional X coordinate
float_t y ; ///< Keypoint fractional Y coordinate
float_t s ; ///< Keypoint fractional scale index
float_t sigma ; ///< Keypoint scale
} ;
typedef std::vector<Keypoint> Keypoints ; ///< Keypoint list datatype
typedef Keypoints::iterator KeypointsIter ; ///< Keypoint list iter datatype
typedef Keypoints::const_iterator KeypointsConstIter ; ///< Keypoint list const iter datatype
.
.
}
.
.
.
}//namespace VL



myFunction()
{
VL::Sift::KeypointsIter VectKeypointsIter;

Keypoints keypoints ;

VectKeypointsIter=keypoints.begin();
}




error C2440: '=' : cannot convert from 'struct std::pair<struct VL::Sift::Keypoint,float> *' to 'struct VL::Sift::Keypoint *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

deopen
دوشنبه 05 اسفند 1387, 12:20 عصر
شما در این کد چند اشتباه داشتید:

1-قبل از اعلان یک vector باید آنرا با استفاده از دستور پیش پردازنده ضمیمه کرد


#include<vector>


2-نوع float_t جز نوع های از قبل تعریف شده نیست,من احتمال دادم که این نوع برابر نوع
unsigned float باشد.

3-(اصلی ترین مشکل) تابع myFunction یا باید تابع عضو باشد یا friend function.
کد اصلاح شده :



//vl.h
#include<vector>
class Sift
{
//friend can access any members of a class
friend void myFunction();//friend declaration
struct Keypoint
{
int o ; ///< Keypoint octave index
int ix ; ///< Keypoint integer X coordinate (unnormalized)
int iy ; ///< Keypoint integer Y coordinate (unnormalized)
int is ; ///< Keypoint integer scale indiex
unsigned float x ; ///< Keypoint fractional X coordinate
unsigned float y ; ///< Keypoint fractional Y coordinate
unsigned float s ; ///< Keypoint fractional scale index
unsigned float sigma ; ///< Keypoint scale
} ;
typedef std::vector<Keypoint> Keypoints ; ///< Keypoint list datatype
typedef Keypoints::iterator KeypointsIter ; ///< Keypoint list iter datatype
typedef Keypoints::const_iterator KeypointsConstIter ; ///< Keypoint list const iter datatype

};





//main.cpp
#include"vl.h"
void myFunction()
{
Sift::KeypointsIter VectKeypointsIter;

Sift::Keypoints keypoints ;

VectKeypointsIter=keypoints.begin();
}

int main() {
return 0;
}