小编pig*_*d10的帖子

不允许使用不完整类型:stringstream

为什么这一行会出错Error: incomplete type is not allowed

stringstream ss;
Run Code Online (Sandbox Code Playgroud)

c++ types stringstream

96
推荐指数
3
解决办法
16万
查看次数

PCH警告:标头停止不能在宏或#if块中 - Visual C++ 2010 Express SP1

这是从一个可能正在运作的网站上粘贴的.我做了一些谷歌搜索,发现我现在的问题是我今天下载的Visual C++ 2010 SP1的结果,现在给我这个错误:

PCH Warning: header stop cannot be in a macro or #if block.

希望有人能够帮助我!

#ifndef APP_STATE_H
#define APP_STATE_H

#include "Framework.h"

class AppState; //this line is giving me the error

//define two classes

#endif
Run Code Online (Sandbox Code Playgroud)

Framework.h:

#ifndef OGRE_FRAMEWORK_H
#define OGRE_FRAMEWORK_H

#include <OgreCamera.h>
#include <OgreEntity.h>
#include <OgreLogManager.h>
#include <OgreOverlay.h>
#include <OgreOverlayElement.h>
#include <OgreOverlayManager.h>
#include <OgreRoot.h>
#include <OgreViewport.h>
#include <OgreSceneManager.h>
#include <OgreRenderWindow.h>
#include <OgreConfigFile.h>

#include <OISEvents.h>
#include <OISInputManager.h>
#include <OISKeyboard.h>
#include <OISMouse.h>

class OgreFramework : public Ogre::Singleton<OgreFramework>,OIS::KeyListener,OIS::MouseListener{
public:
    OgreFramework();
    ~OgreFramework();

    bool …
Run Code Online (Sandbox Code Playgroud)

c++ visual-c++

68
推荐指数
3
解决办法
6万
查看次数

std :: to_string - 超过重载函数的实例与参数列表匹配

counter 是一个 int

void SentryManager::add(std::string name,std::shared_ptr<Sentry>){
    name = name + std::to_string(counter);
}
Run Code Online (Sandbox Code Playgroud)

什么是阻止此错误的最佳方法?当我懒惰时,我只是制作了int long long(或其他东西),但我确信有更好的解决方法.

错误信息:

sentrymanager.cpp(8): error C2668: 'std::to_string' : ambiguous call to overloaded function
Run Code Online (Sandbox Code Playgroud)

我正在使用Visual C++ 2010 Express.

c++ visual-studio-2010 visual-c++ c++11

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

错误:无法访问功能

我收到了这个错误,但我认为如果会员的保护级别太高并且无法访问它我只能得到它,但无论如何我都会得到它.

Shopable.h:

#ifndef _SHOPABLE_H_
#define _SHOPABLE_H_

#include "Library.h"

class Shopable{
private:
    std::string Name;
    int Cost;
    std::string Description;
public:
    std::string getName() const{return Name;}
    int getCost() const {return Cost;}
    virtual std::string getDesc() const = 0;
};

#endif
Run Code Online (Sandbox Code Playgroud)

Weapon.h:

#ifndef _WEAPON_H_
#define _WEAPON_H_

#include "Globals.h"
#include "Shopable.h"

class Weapon : Shopable{
private:
    int Damage;
public:
    Weapon(int Cost,int Damage,std::string Name) : Cost(Cost), Damage(Damage), Name(Name){}
    std::string getDesc() const{
        return getName()+"\t"+tostring(Damage)+"\t"+tostring(Cost);
    }
    int Damage(Entity *target){
        int DamageDealt = 0;
        //do damage algorithm things here
        Special();
        return …
Run Code Online (Sandbox Code Playgroud)

c++ inheritance protection

25
推荐指数
5
解决办法
5万
查看次数

std没有会员'getline'?

我正在尝试使用std :: getline,但是我的编译器告诉我getline没有被识别出来?

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <fstream>
#include <cstdlib>

int main(){
    using namespace std;
    string line;
    ifstream ifile("test.in");
    if(ifile.is_open()){
        while(ifile.good()){
            getline(ifile,line);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c++ io std getline

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

常量映射迭代器不会设置为mymap.begin()

map<string,Shopable*>::iterator it = mymap.begin();
Run Code Online (Sandbox Code Playgroud)

迭代器似乎是常量,但items.begin()不返回常量迭代器.或者,这就是我的想法,因为鼠标悬停错误是这样的:

"No conversion from 'std::Tree_const_iterator<...> to std::Tree_iterator<...> exists'".
Run Code Online (Sandbox Code Playgroud)

为什么?

c++ iterator constants map

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

在VS2013中初始化std :: discrete_distribution

我有一个std::vector<float> weights;包含权重列表.在运行该程序的某个阶段之前,我不知道该列表中的内容.我想要做

std::discrete_distribution<> dist(weights.begin(),weights.end());
Run Code Online (Sandbox Code Playgroud)

但VS2013似乎没有std :: discrete_distribution的构造函数,它接受迭代器范围.有没有解决方法?

c++ std c++-standard-library c++11 visual-studio-2013

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

多个定义的符号C++错误

我想ifndef something #define something body #endif解决了这个错误,所以我不确定为什么会这样.

//Library.h
#ifndef __LIBRARY__
#define __LIBRARY__

#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdarg>
#include <vector>
#include <ctime>
#include <cmath>
#include <cstdlib>

//file includes
#include "Globals.h"

using namespace std;

#endif //__LIBRARY__
Run Code Online (Sandbox Code Playgroud)

-

//globals.h
//global variables
#ifndef __GLOBAL__
#define __GLOBAL__

#include <vector>
#include <iostream>
#include <string>

//prototypes
bool Poglathon(std::vector<std::string>& text);
void NPCTalk(std::string const& speaker,std::vector<std::string> const& text);
void wait(double seconds);

//player stats
std::string name;
double str;     //strength
double wis;     //wisdom
double …
Run Code Online (Sandbox Code Playgroud)

c++ linker symbols

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

C++ 中的字符串变量参数列表

我正在尝试使用可变参数列表来使基于文本的 RPG 中的 NPC 轻松交谈。有这么多错误,我什至懒得发布它们 - 我想我使用这个太错误了,你不需要输出。如果你这样做,我当然会发布它。

这是您需要的两个文件:

//Globals.h

#ifndef _GLOBALS_
#define _GLOBALS_

//global variables

#include "Library.h"
//prototypes
bool Poglathon();
void NPCTalk(string speaker,string text,...);

//functions
void NPCTalk(string speaker,string text,...){
    va_list list;
    va_start(list,text);
    while(true){
        string t = va_arg(list,string);
        if (t.compare("")==0)
            break;
        cout << speaker << ": "<< t << endl << endl;
        system("PAUSE");
    }
}

#endif
Run Code Online (Sandbox Code Playgroud)

另一个:

//Library.h

#ifndef _LIBRARY_H_
#define _LIBRARY_H_

#include <iostream>
using namespace std;

#include "Globals.h"
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdarg>

#endif
Run Code Online (Sandbox Code Playgroud)

c++ string arguments list variadic-functions

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

什么时候应该让课程不可复制?

根据谷歌风格指南,"很少有类需要复制.大多数应该既没有复制构造函数也没有赋值运算符."

他们建议您使类不可复制(即,不给它复制构造函数或赋值运算符),而是建议在大多数情况下通过引用或指针传递,或使用无法隐式调用的clone()方法.

但是,我听到了一些反对这一点的论点:

  • 访问引用(通常)比访问值慢.
  • 在某些计算中,我可能希望保留原始对象,只返回已更改的对象.
  • 我可能想将计算的值存储为函数中的本地对象并返回它,如果我通过引用返回它,我就无法做到.
  • 如果一个类足够小,则通过引用传递较慢.

遵循本指南的正面/负面是什么?是否有任何标准的"经验法则"使类不可复制?创建新类时我应该考虑什么?

c++ class copy-constructor assignment-operator

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