小编mil*_*bug的帖子

std::integral_constant<ch​​ar*, "kernel32.dll"> 无法编译?

我想从 char* 和“kernel32.dll”中得到积分常数,但总是失败。以下是我失败的尝试,谁能告诉我正确的用法?

error 1: cout << std::integral_constant<const char*, "kernel32.dll">::value << endl;
error 2: cout << std::integral_constant<char*, "kernel32.dll">::value << endl;
error 3: cout << std::integral_constant<char[], "kernel32.dll">::value << endl;
error 4: cout << cout << std::integral_constant<char*, static_cast<char*>("kernel32.dll")>::value << endl;
Run Code Online (Sandbox Code Playgroud)

以上 4 条语句具有相同的错误信息。:

Console.cpp(181): error C2762: 'std::integral_constant' : invalid expression as a template argument for '_Val'
1>          D:\Programfiles\Visual Studio 2013\VC\include\xtr1common(35) : see declaration of 'std::integral_constant'
1>Console.cpp(181): error C2955: 'std::integral_constant' : use of class template requires template argument list
1>          D:\Programfiles\Visual Studio 2013\VC\include\xtr1common(35) …
Run Code Online (Sandbox Code Playgroud)

c++ templates c++11 visual-studio-2012

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

在返回值上调用std :: move - 签名应该是什么

考虑

class X
{
public:
    std::unique_ptr<int> m_sp;
    A m_a;

    A test1()
    {
        return std::move(m_a);
    }

    A&& test2()
    {
        return std::move(m_a);
    } 

    std::unique_ptr<int> test3()
    {
        return std::move(m_sp);
    }

    std::unique_ptr<int>&& test4()
    {
        return std::move(m_sp);
    }

    std::unique_ptr<int> test5()
    {
        return std::make_unique<int>(50);
    }
};

class A
{
public:
    A()
    {
        m_i = 1;
    }

    A(A&& other)
    {
        this->m_i = other.m_i;
        other.m_i = -1;
    }

    A& operator=(A&& other)
    {
        this->m_i = other.m_i;
        other.m_i = -1;
        return *this;
    }

    int m_i;
};
Run Code Online (Sandbox Code Playgroud)

练习这些课程

X x;
A …
Run Code Online (Sandbox Code Playgroud)

c++ move rvalue-reference c++11

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

为什么我在开发c ++中使用"cin函数"后不能使用"获取函数"?

这是我的代码:

#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>

main()
{
      char a[120];
      int b;

      cout<<"age : ";
      cin>>b;

      cout<<"Name : ";
      gets(a);

      cout<<"Name : "<<a<<endl;
      cout<<"age  : "<<b;
      cout<<endl;

      system("pause");
      return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:年龄:20 //我输入20名称:名称://不要求输入名称.年龄:20按任意键继续...

但是,如果我先使用gets(a),那就没关系.

#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>

main()
{
      char a[120];
      int b;

      cout<<"Name : ";
      gets(a);

      cout<<"age : ";
      cin>>b;

      cout<<"Name : "<<a<<endl;
      cout<<"age  : "<<b;
      cout<<endl;

      system("pause");
      return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:姓名:约翰//我输入约翰.年龄:20 //我打20.

姓名:John年龄:20按任意键继续......

他们怎么了......请帮忙......

c++ dev-c++

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

结构c ++向量

我在创建结构矢量时遇到问题.在我的函数AddApp中,我无法将新分配的结构"推回"到向量中.我收到错误消息"无效的参数".我四处看看是否有人有类似的问题,但没有任何帮助.任何人都可以指出我的逻辑中的缺陷是什么?谢谢.

class AppHolder
{
private:
    struct Info
    {
    int refNumber;
    string name;
    string link;
    };

vector<Info> dataBase;

public:
    void AddApp(int ,string ,string );
};

void AppHolder::AddApp(int R, string N, string L)
{
Info *newApp = new Info;
newApp -> name = N;
newApp -> link = L;
newApp -> refNumber = R;

dataBase.push_back(newApp);
}
Run Code Online (Sandbox Code Playgroud)

c++ vector

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

如何定义物理常数的结构?

我想定义某种物理常数的结构(结构?名称空间?类?),这对于我的程序是全局性的。这样做的目的是使我能够为常数提供简单直观的名称,同时在其他地方保护这些值。例如,我可以在此结构中将q定义为基本电荷,而不必担心在程序的其他地方意外地将q用作循环变量。我的想法是定义一个结构(在main.h中):

struct constants {
    float q=1.6022e-19;
} _C;
Run Code Online (Sandbox Code Playgroud)

但这给了我错误

main.h:79: error: ISO C++ forbids initialization of member 'q'
main.h:79: error: making 'q' static
main.h:79: error: ISO C++ forbids in-class initialization of non-const static member 'q'
Run Code Online (Sandbox Code Playgroud)

我在这里和整个互联网上都进行了搜索,但没有找到答案。如果您知道其中之一,请重定向我。我对Stack Overflow和C / C ++还是相当陌生,因此感谢您的耐心配合。

c++

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

当它不应该是C++时,逻辑比较失败

我一直有一个问题,这个比较if (code->at(i) == guess.at(i)) 失败了,即使它不应该因为它们都是'0':http://puu.sh/bvCRB/c640fb85a4.png

guess是炭的向量s(vector<char> guess){ 和code是一个指向炭的矢量vector<char> * code

c++ vector

-3
推荐指数
1
解决办法
88
查看次数