首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

C++ template vector 有关问题

2012-03-21 
C++ template vector 问题MyVector.h#ifndef _MYVECTOR_H_#define _MYVECTOR_H_#include cmath#include

C++ template vector 问题
MyVector.h

#ifndef _MYVECTOR_H_
#define _MYVECTOR_H_

#include <cmath>
#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;

template <typename T>
class MyVector {
public:
MyVector ();
~MyVector ();
  ........
  ......
  ......
private:
  std::vector<T> vPoint;
};

template <typename T>
inline MyVector<T> operator* (const T val, const MyVector<T>& myVector) {
  return myVector * val;
}

template <typename T>
std::ostream& operator<<(std::ostream& stream, const MyVector<T>& myVector) {
  stream << fixed;
  stream << setprecision(2); 
  for (int i=0; i<myVector.getDimension(); i++) {
  stream << myVector[i] << " ";
  }
  return stream;
}

#include "MyVector.cpp"

#endif 


MyVector.cpp
#include "MyVector.h"

template <typename T>
MyVector<T>::MyVector(){

}

template <typename T>
MyVector<T>::~MyVector (){

}
........


Debug时问题
Multiple markers at this line
- redefinition of ‘MyVector<T>::MyVector()’
- ‘MyVector<T>::MyVector()’ previously declared here

大家指点一下......


[解决办法]
看你这个错误 应该是你的CPP 里面也需要
#ifndef MyVector_CPP
#define MyVector_CPP

//code

#endif

热点排行