为什么这一行会出错Error: incomplete type is not allowed
?
stringstream ss;
Run Code Online (Sandbox Code Playgroud) 这是从一个可能正在运作的网站上粘贴的.我做了一些谷歌搜索,发现我现在的问题是我今天下载的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) 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.
我收到了这个错误,但我认为如果会员的保护级别太高并且无法访问它我只能得到它,但无论如何我都会得到它.
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) 我正在尝试使用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) 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)
为什么?
我有一个std::vector<float> weights;
包含权重列表.在运行该程序的某个阶段之前,我不知道该列表中的内容.我想要做
std::discrete_distribution<> dist(weights.begin(),weights.end());
Run Code Online (Sandbox Code Playgroud)
但VS2013似乎没有std :: discrete_distribution的构造函数,它接受迭代器范围.有没有解决方法?
我想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) 我正在尝试使用可变参数列表来使基于文本的 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) 根据谷歌风格指南,"很少有类需要复制.大多数应该既没有复制构造函数也没有赋值运算符."
他们建议您使类不可复制(即,不给它复制构造函数或赋值运算符),而是建议在大多数情况下通过引用或指针传递,或使用无法隐式调用的clone()方法.
但是,我听到了一些反对这一点的论点:
遵循本指南的正面/负面是什么?是否有任何标准的"经验法则"使类不可复制?创建新类时我应该考虑什么?
c++ ×10
c++11 ×2
std ×2
visual-c++ ×2
arguments ×1
class ×1
constants ×1
getline ×1
inheritance ×1
io ×1
iterator ×1
linker ×1
list ×1
map ×1
protection ×1
string ×1
stringstream ×1
symbols ×1
types ×1