小编Cha*_*han的帖子

C++中的迭代器类如何工作?

我试图理解迭代器的实现,在玩源时,我看到了这样的说法:

typedef output_iterator_tag iterator_category;
Run Code Online (Sandbox Code Playgroud)

我不明白这个typedef是如何在课堂上工作的?它提供的副作用是什么?谁能跟我走过这个?

c++ stl

11
推荐指数
1
解决办法
4046
查看次数

back_inserter如何工作?

我正在努力了解如何back_inserter工作,这是我从SGI-STL获得的实现:

template<class C>
class back_insert_iterator {
protected:
    C* container;
public:
    typedef C                   container_type;
    typedef output_iterator_tag iterator_category;
    typedef void                value_type;
    typedef void                difference_type;
    typedef void                pointer;
    typedef void                reference;

    explicit back_insert_iterator( C& __x ) :container( &__x ) { 
    }

    back_insert_iterator<C>& operator=( const typename C::value_type& val ) { 
        container->push_back( val );
        return *this;
    }

    back_insert_iterator<C>& operator*() {  
        return *this;  
    }

    back_insert_iterator<C>& operator++() {  
        return *this;  
    }

    back_insert_iterator<C>& operator++( int ) {  
        return *this;  
    }
};
Run Code Online (Sandbox Code Playgroud)

我理解大多数部分,除了最后三个运算符*,++,++(int).我对它们存在的猜测是因为它们需要在置于STL算法内时支持操作.除此之外,我不知道他们用的是什么?任何人都可以帮我澄清一下吗?

谢谢,

c++ stl

11
推荐指数
1
解决办法
6755
查看次数

帮助解释Scheme中的"cons"如何工作?

这是删除列表最后一个元素的函数.

(define (remove-last ll)
  (if (null? (cdr ll))
      '()
      (cons (car ll) (remove-last (cdr ll)))))
Run Code Online (Sandbox Code Playgroud)

所以根据我的理解,如果我们cons是一个列表(例如,a b c有一个空列表,即'()我们应该得到 a b c.但是,在交互窗口(DrScheme)中测试,结果是:

如果(cons'()'(abc))

(() a b c)
Run Code Online (Sandbox Code Playgroud)

如果(cons'(abc)'())

((a b c))
Run Code Online (Sandbox Code Playgroud)

我喜欢哎呀:(然后我回到我的问题,删除所有相邻重复的元素.例如, (a b a a c c)将是(a b).

(define (remove-dup lst)
  (cond ((null? lst) '())
        ((null? (cdr lst)) (car lst))
        ((equal? (car lst) (car (cdr lst))) (remove-dup (cdr (cdr lst))))
        (else (cons (car lst) (car (cdr lst))))
        )

  )
Run Code Online (Sandbox Code Playgroud)

这不正确,但我意识到答案 …

scheme

11
推荐指数
1
解决办法
4万
查看次数

有没有办法用类实例指针调用构造函数?

我们可以通过类指针显式调用析构函数,为什么不是构造函数?任何的想法?

#include <iostream>

class Con {
public:
    Con( int x ) : x( x ) {

    }

private:
    int x;
};

int main() {
    Con* c = new Con( 1 );
    //c->Con( 2 ); //illegal
    c->~Con(); // ok!
    delete c;
}
Run Code Online (Sandbox Code Playgroud)

谢谢,

c++

11
推荐指数
2
解决办法
2万
查看次数

缓存如何在JAX-RS中运行?

假设我使用@GET方法调用以下Web服务:

@GET
@Path(value = "/user/{id}")
@Produces(MediaType.APPLICATION_JSON)
public Response getUserCache(@PathParam("id") String id, @Context HttpHeaders headers) throws Exception {
    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("id", id);
    SqlSession session = ConnectionFactory.getSqlSessionFactory().openSession();
    Cre8Mapper mapper = session.getMapper(Cre8Mapper.class);

    // slow it down 5 seconds
    Thread.sleep(5000);

    // get data from database
    User user = mapper.getUser(map);

    if (user == null) {
        return Response.ok().status(Status.NOT_FOUND).build();
    } else {
        CacheControl cc = new CacheControl();
        // save data for 60 seconds
        cc.setMaxAge(60);
        cc.setPrivate(true);
        return Response.ok(gson.toJson(user)).cacheControl(cc).status(Status.OK).build();
    }
}   
Run Code Online (Sandbox Code Playgroud)

为了实验,我在从数据库中获取数据之前5秒放慢当前线程的速度. …

java web-services http jax-rs http-caching

11
推荐指数
2
解决办法
7782
查看次数

如何修复由MySql Connector C++引起的未解析的外部符号?

我按照本教程http://blog.ulf-wendel.de/?p=215#hello.我在Visual C++ 2008和Visual C++ 2010上都尝试过.无论是静态还是动态,编译器都给了我相同的确切错误消息:

error LNK2001: unresolved external symbol _get_driver_instance
Run Code Online (Sandbox Code Playgroud)

有没有人以前遇到过这个问题?

更新:
+其他依赖项:mysqlcppconn.lib
+其他包含目录:C:\ Program Files\MySQL\MySQL Connector C++ 1.0.5\include
+其他库目录:C:\ Program Files\MySQL\MySQL Connector C++ 1.0.5\LIB \选择

另一个更新:点击链接到的get_driver_instance()上的F12:

class CPPCONN_PUBLIC_FUNC Driver
{
protected:
    virtual ~Driver() {}
public:
    // Attempts to make a database connection to the given URL.

    virtual Connection * connect(const std::string& hostName, const std::string& userName, const std::string& password) = 0;

    virtual Connection * connect(std::map< std::string, ConnectPropertyVal > & options) = 0;

    virtual int getMajorVersion() = 0; …
Run Code Online (Sandbox Code Playgroud)

c++ mysql

9
推荐指数
2
解决办法
1万
查看次数

我们应该在WPF之前学习窗体吗?

有学习曲线吗?我想拿起Windows Form,但在阅读关于WF vs WPF的许多帖子时,我完全被WPF说服了.我该怎么办?

.net c# wpf winforms

9
推荐指数
1
解决办法
1189
查看次数

如何在boost :: filesystem中使用copy_file?

我想将一个文件从目录复制到另一个文件,但我的程序总是因为某些原因而中止.有没有人这样做之前可以告诉我出了什么问题?我怎么能抓住异常被抛出copy_file,我检查了boost网站,但我找不到任何有关异常的相关信息.

path user_path( "C:\\My Folder" );
boost::filesystem::create_directory( user_path );
path file(  "C:\\Another\\file.txt" );
boost::filesystem::copy_file( file, user_path );
Run Code Online (Sandbox Code Playgroud)

谢谢,

c++ boost boost-filesystem

8
推荐指数
1
解决办法
1万
查看次数

如何在Scheme函数中声明变量?

有可能这样做吗?假设我想获取列表的最后一个元素,我将创建一个变量i = 0,并将其递增直到它等于长度.任何的想法?一个例子将不胜感激.

谢谢,

scheme

8
推荐指数
1
解决办法
2万
查看次数

如何使用ListView实现自定义BaseAdapter的过滤器?

这是我从BaseAdapter继承的自定义适配器:

public class LocationItemAdapter extends BaseAdapter implements Filterable {
    private Activity context;
    private String[] names;
    private Bitmap[] iconBitmaps;
    private String[] categories;
    private String[] ratings;
    private boolean notifyChanged = true;

    public LocationItemAdapter(Activity activityContext, String[] names, Bitmap[] iconBitmaps, String[] categories, String[] ratings) {
        super();
        this.context = activityContext;
        this.names = names;
        this.iconBitmaps = iconBitmaps;
        this.categories = categories;
        this.ratings = ratings;
    }

    public int getCount() {
        return names.length;
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position; …
Run Code Online (Sandbox Code Playgroud)

android listview filter

8
推荐指数
1
解决办法
2728
查看次数