如何使用boost :: shared_ptr [英] How to use boost::shared_ptr

查看:59
本文介绍了如何使用boost :: shared_ptr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我是新来提升图书馆的人.我对如何使用它一无所知.在一些教程中,我得到了一个使用Boost库的示例程序.我简单地在VS2005中将其复制并尝试运行它.

以下是我尝试过的代码.

Hi Everyone,

I am new to boost library. I don''t have any idea about how to use it. In some tutorial i got a sample program which uses boost library. i simpley copied it in VS2005 and tried running it.

Below is the code which i tried.

#include <vector>
#include <iostream>
#include <algorithm>
#include <boost/shared_ptr.hpp>

struct Foo
{ 
  Foo( int _x ) : x(_x) {}
  ~Foo() 
  { 
	  std::cout << "Destructing a Foo with x=" << x << "\n"; 
  }
  int x;
};

typedef boost::shared_ptr<Foo> FooPtr;

struct FooPtrOps
{
	bool operator()( const FooPtr & a, const FooPtr & b )
	{ 
		return a->x < b->x; 
	}

	void operator()( const FooPtr & a )
	{ 
		std::cout << " " << a->x; 
	}
};

int main()
{
  std::vector<FooPtr> foo_vector;

  foo_vector.push_back( FooPtr(new Foo(3)) );
  foo_vector.push_back( FooPtr(new Foo(2)) );
  foo_vector.push_back( FooPtr(new Foo(1)) );

  std::cout << "Original foo_vector:";
  std::for_each( foo_vector.begin(), foo_vector.end(), FooPtrOps() );
  std::cout << "\n";

  std::sort( foo_vector.begin(), foo_vector.end(), FooPtrOps() );

  std::cout << "Sorted foo_vector:";
  std::for_each( foo_vector.begin(), foo_vector.end(), FooPtrOps() );
  std::cout << "\n";
  system("pause");
  return 0;
}




但是当我编译此代码时,编译器给出了错误提示

严重错误C1083:无法打开包含文件:``boost/shared_ptr.hpp'':没有这样的文件或目录

我不知道是否需要更改或进行一些配置才能将Boost与VS2005集成在一起.

请帮忙.

在此先谢谢您.




But when i compile this code compiler given error stating

fatal error C1083: Cannot open include file: ''boost/shared_ptr.hpp'': No such file or directory

I don''t know if i need to change or do some configuration in order to integrate Boost with VS2005.

Please help.

Thanks in advance.

推荐答案

无法打开包含文件:"boost/shared_ptr.hpp":没有这样的文件或目录
您必须:
Cannot open include file: ''boost/shared_ptr.hpp'': No such file or directory
You have to:

  1. 下载Boost库.
  2. 在VS2005中相应地设置目录"选项.


我不再安装2005,但是在2008中,它位于Tools \ Options下,然后在Projects And Solutions \ VC ++目录下.从那里选择包含文件夹".
仔细搜索如何在VC ++ 2005中使用BOOST"不会受到伤害.

希望这会有所帮助,
巴勃罗.


I no longer have an installation of 2005, but in 2008 it is under Tools\Options, and then Projects And Solutions\VC++ Directories. From there, pick ''Include Folders''.
Googling a bit for ''How to use BOOST with VC++ 2005'' won''t hurt.

Hope this helps,
Pablo.


这篇关于如何使用boost :: shared_ptr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆