小编Jer*_*fin的帖子

如何在模板化的类中声明模板化的map :: iterator.下面的代码说; 编译时预计

以下代码表示错误:expected';' 在'forwit'错误之前:预期';' 在'revit'之前

template<class T>
class mapping {

public:
    map<T,int> forw;
    map<int,T> rev;
    int curr;
    //typeof(forw)::iterator temp;
    map<T,int>::iterator forwit;
    map<int,T>::iterator revit;
};

//    }; // JVC: This was present, but unmatched.
Run Code Online (Sandbox Code Playgroud)

我完全不知道问题是什么?请帮忙.

提前致谢

c++ templates stl compiler-errors map

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

SQL Server 2008中的表上的WITH(NOLOCK)

在我的SQL tempOrder表中有数百万条记录,并有10个触发器tempOrder用另一个表的更新来更新表.

所以我想with(NOLOCK)在桌子上申请申请.

我知道

SELECT * FROM temporder with(NOLOCK)

我可以做这个陈述.但有没有办法with(NOLOCK)从SQL Server 2008直接应用于表.

sql-server sql-server-2008

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

寻找最短的子段

我想知道我应该应用哪种算法。

他们是给定的句子和单词列表。我们必须找到包含单词列表中所有单词的第一个最短子段。

例如:

句子 - 这是我解决过的最好的问题

单词列表 -

最好的事物

这个

答案应该是:

这是最好的

如果有很多这样的子段,那么我们必须打印包含最少单词并出现在句子中的第一个子段。

string algorithm

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

C++ std :: reference_wrapper如何隐式转换为引用?

我最近开始使用这std::reference_wrapper门课.当替换原始引用的某些用法时,我注意到我没有必要使用该get()函数将reference_wrappers作为参数传递给采用普通引用的函数.

void foo(const T& a);
//...
T obj;
std::reference_wrapper<const T> ref(obj);
foo(ref);  //works!
//foo(ref.get()); also works, but I expected that it would be required
Run Code Online (Sandbox Code Playgroud)

std::reference_wrapper当它传递给函数时,如何隐式转换为原始引用?

c++ reference implicit-conversion c++11 reference-wrapper

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

将 int 转换为 float?

每当我尝试编译时,我都会得到

24 [警告] 转换为intfromfloat

83 [警告] 转换为intfromfloat

int a , b = 8;
float c = 5.2;
float d = 8E3;
a = static_cast<float>(b) * c; // 24
cout << a << "\n";
cout << d << "\n";


int x, y, answer;
x = 7;
y = 9;
answer = 5;
answer *= (x + y);
cout << answer << "\n";


answer *= x + y;
cout << answer << "\n";


float m = …
Run Code Online (Sandbox Code Playgroud)

c++

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

为什么它可以用GNU/C++编译,无法在VC++ 2010 RTM中编译?

#include <stdlib.h>
#include <iostream>
#include <memory>
#include "copy_of_auto_ptr.h"
#ifdef _MSC_VER
#pragma message("#include <string>")
#include <string>
// http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html#Diagnostic-Pragmas
#endif

/*
 case 1-4 is the requirement of the auto_ptr.
 which form http://ptgmedia.pearsoncmg.com/images/020163371X/autoptrupdate/auto_ptr_update.html
*/
/*
 case 1.
 (1) Direct-initialization, same type, e.g.
*/
std::auto_ptr<int> source_int() {
    // return std::auto_ptr<int>(new int(3));
    std::auto_ptr<int> tmp(new int(3));
    return tmp;
}

/*
 case 2.
 (2) Copy-initialization, same type, e.g.
*/
void sink_int(std::auto_ptr<int> p) {
    std::cout << "sink_int << " << *p << std::endl;
}

/*
 case 3.
 (3) …
Run Code Online (Sandbox Code Playgroud)

c++ gnu auto-ptr

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

致命错误C1016:#if [n] def期望一个标识符

// File: Lab13Frac.h

#include <iostream>
using namespace std;
#ifndef "Lab13Frac.h"
#define "Lab13Frac.h"

// prototpes

#endif 
Run Code Online (Sandbox Code Playgroud)

c++ compiler-errors

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

命令行参数

我正在努力尝试用Visual生成的C++代码做一些琐碎的事情.这令人沮丧,超出预期.

我习惯于从命令行获取参数,这要归功于:

int main(int argc, char** argv)
Run Code Online (Sandbox Code Playgroud)

好的,这是有效的,至少只要我们留在ANSI世界.

现在,Visual生成了这个:

int main(array<System::String ^> ^args)
Run Code Online (Sandbox Code Playgroud)

关于如何使用这条线,我有点无能为力.我显然试图将未知语义与更熟悉的语义交换,但编译失败.我也一直在互联网上漫游大量的时间,为这种情况找到了很多例子,但是没有一个能够工作......

[编辑]关于我正在尝试做什么的小解释:这应该是一个微不足道的GUI程序.它从命令行参数获取文件路径,并根据用户在GUI上选择的选项写入.所以:它不是CLI,它是一个Windows窗体.

c++-cli visual-c++

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

在Metro/C++中通过引用传递字符串?

我正在开发一个C++ Metro风格的应用程序,必须通过引用传递一个字符串(不知何故).起初,我传递了String ^,它不起作用,因为字符串是不可变的我是如何找到的.

通过引用传递字符串的正确方法是什么?

编辑:好的,似乎这并不容易,因为答案和评论建议使用返回值.但据我认为这在我的情况下不适用:在这个Metro应用程序中,我有两个页面,并且这两个页面应该"共享"一个字符串.
所以在主页面中我在点击事件中这样做:
this->Frame->Navigate(newPage, this->TestString);

在第二页的OnNavigatedTo事件中,我将第二个参数转换为String ^并更改它.然后我用this->Frame->GoBack()它导航回第一页.在那里,我想访问更改的字符串.不幸的是,就我所知,GoBack()不允许传递任何参数.

string c++-cli reference microsoft-metro

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

如果键不存在,设置无序映射的默认值

在我的程序中,如果我的无序映射中不存在某个键,我希望默认值将是 而std::numeric_limits<double>::max()不是 0。

我的代码如下所示:

class Pair
{
public:
   Graph::NodeId node;
   bitset<64> bits;

   Pair(Graph::NodeId node1, double bits1)
   {
       node = node1;
       bitset<64> temp(bits1);
       bits = temp;
   }

};

bool operator==(const Pair &P1, const Pair &P2)
{
   return P1.node == P2.node && P1.bits == P2.bits;
}

template <>
struct std::hash<Pair>
{
std::size_t operator()(const Pair &pair) const noexcept
{
  std::hash<decltype(pair.node)> ihash;
  std::hash<decltype(pair.bits)> bhash;
  return ihash(pair.node) * 31 + bhash(pair.bits);
}
};

unordered_map<Pair, double> lFunction;
Run Code Online (Sandbox Code Playgroud)

因此,如果我想访问该元素lFunction[Pair(3,3)]并且键不存在,则应该存在 value std::numeric_limits<double>::max()

c++ hash unordered-map

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