以下程序显示错误:
#include<conio.h>
#include<iostream.h>
int count = 0;
class alpha
{
public:
alpha()
{
count++;
cout<<"\n Number of objects created "<<count;
}
~alpha()
{
cout<<"\n Number of object destroyed"<<count;
count--;
}
};
int main
{
cout<<" inside main ";
alpha a1, a2, a3, a4;
{
cout<<"\n Block 1 ";
alpha A5;
}
{
cout<<"\n Block 2 ";
alpha a6;
}
cout<<" main again ";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
第11行:错误:由于-Wfatal-errors,对'count'的引用是模糊的编译终止.
在下面的代码中,当我输入为1 10 2 1 2 2时,总和打印为52,sum3打印为31.200001,而它的输入为31.200000
int main(){
int t,n,i,a[2000],m,j,f;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
scanf("%d",&f);
for(i=0;i<f;i++){
scanf("%d",&a[i]);
}
scanf("%d",&m);
if(n!=0){
int sum=n*(n+1)/2;
int sum2=0;
for(j=0;j<i;j++){
sum2+=a[j];
}
sum-=sum2;
printf("%d\n",sum);
float sum3;
if(n%2==0) sum3=(1.0-2.0*m/n)*sum;
else sum3=(1.0-2.0*m/(n+1))*sum;
printf("%f\n",sum3);
}
else printf("0.0000\n");
}
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我有一个基本多态类(使用虚方法)并从中派生出来.我想使用以下代码
boost::shared_ptr<base_class> ptr( new derived_class() );
Run Code Online (Sandbox Code Playgroud)
但编译器返回以下错误
cannot convert ‘fpga_northwest*’ to ‘fpga*’ in initialization
make: *** [../obj/ixecute_cmd_interface.o] Error 1
Run Code Online (Sandbox Code Playgroud)
看看周围我很想使用以下构建正常,但我有一些疑问.你认为这是正确的吗?
boost::shared_ptr<base_class> ptr_base;
boost::shared_ptr<derived_class> ptr_derived( new derived_class() );
ptr_base = boost::dynamic_pointer_cast<base_class>( ptr_derived );
Run Code Online (Sandbox Code Playgroud)
如果我使用boost::static_pointer_cast我有编译器错误; 既然我从一个衍生到一个基础的铸造应该不是更正确的一个static_cast?
谢谢你的帮助
我在嵌入式c工作了一个月,直到现在我遇到了简单的循环,如:
for(i=0;i<10;i++)
Run Code Online (Sandbox Code Playgroud)
但现在我遇到了一种新的for循环,它是:
for(t=0; string[t]; ++t)
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我这个循环是如何工作的.示例代码是:
#include <stdio.h>
#include <ctype.h>
void print_upper(char *string);
int main(void)
{
char s[80];
printf("Enter a string: ");
gets(s);
print_upper(s);
printf(''\ns is now uppercase: %s", s);
return 0;
}
/* Print a string in uppercase. */
void print_upper(char *string)
{
register int t;
for(t=0; string[t]; ++t)
{
string[t] = toupper(string[t]);
putchar(string[t]);
}
}
Run Code Online (Sandbox Code Playgroud) 是否可以使用std :: for_each或其他类似的东西?
#include <list>
#include <algorithm>
// Class declaration
//
struct Interface
{
virtual void run() = 0;
};
struct A : public Interface
{
void run() { std::cout << "I run class A" << std::endl; }
};
struct B : public Interface
{
void run() { std::cout << "I run class B" << std::endl; }
};
// Main
//
int main()
{
// Create A and B
A a;
B b;
// Insert it inside a list
std::list<Interface …Run Code Online (Sandbox Code Playgroud) 有人可以为表达式绘制优先级树,请在C中进行表达式求值后解释副作用.值.
int i=-3, j=2, k=0, m;
m= ++i || ++j&&++k;
Run Code Online (Sandbox Code Playgroud)
根据我输出应该是-2 3 1 1但我的gnu c编译器打印是-2 2 0 1?我想知道怎么样?
m_MAX和ask()由run()使用,但不应该是公共的.怎么能/应该这样做?
#include <vector>
class Q {
public:
static int const m_MAX=17;
int ask(){return 4;}
};
class UI {
private:
std::vector<Q*> m_list;
public:
void add(Q* a_q){m_list.push_back(a_q);}
int run(){return Q::m_MAX==m_list[0]->ask();}
};
int main()
{
UI ui;
ui.add(new Q);
ui.add(new Q);
int status = ui.run();
}
Run Code Online (Sandbox Code Playgroud) 在定义我的Element类时,我收到以下错误:
no matching function for call to ‘Dict::Dict()’ word1.cpp:23:
note: candidates are: Dict::Dict(std::string) word1.cpp:10:
note: Dict::Dict(const Dict&)
Run Code Online (Sandbox Code Playgroud)
我没有打电话给任何人,我只是让Element从Dict继承.这有什么问题?
另一个错误是在我的Word类构造函数中我得到以下内容:
In constructor ‘Word::Word(std::string)’: word1.cpp:71:
note: synthesized method ‘Element::Element()’ first required here
Run Code Online (Sandbox Code Playgroud)
在这一点上我真的很沮丧,因为对我来说一切似乎都没问题.
#include <iostream>
#include <vector>
#include <sstream>
#include <string.h>
#include <fstream>
using namespace std;
class Dict {
public:
string line;
int wordcount;
string word;
vector <string> words;
Dict(string f) {
ifstream in(f.c_str());
if (in) {
while (in >> word) {
words.push_back(word);
}
}
else cout << "ERROR couldn't open file" …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用在OpenGL ES 2.0中工作的立方体贴图进行反射贴图.我不确定我是否正确计算反射方向以传递到片段着色器中的samplerCube.
首先,我有Projection,Model和View矩阵以及一个组合的ModelView矩阵.这是我在GLSL中的顶点着色器的代码:
attribute vec4 Position;
attribute vec3 Normal;
uniform mat4 Projection;
uniform mat4 ModelView;
uniform mat3 Model;
uniform mat4 ModelViewProjectionMatrix;
uniform vec3 EyePosition;
varying vec3 ReflectDir;
void main()
{
gl_Position = Projection * ModelView * Position;
mediump vec3 EyeDir = normalize(Position.xyz - EyePosition);
// Reflect eye direction by normal, and transform to world space
ReflectDir = Model * reflect(EyeDir, Normal);
}
Run Code Online (Sandbox Code Playgroud)
我的假设是EyeDirection必须在对象空间中.(正确?)如何在对象空间中获取EyePosition?我是否只是通过逆ModelView矩阵变换摄像机位置(即总是在OpenGL中的{0,0,0}?)?
我试过这个但是我的片段着色器将所有颜色都着色,好像ReflectDir不正确.
有没有人有一个在Xcode中工作的OpenGL ES 2.0反射映射(带有samplerCube)的工作示例?
我正在用c ++制作一个简单的蛇游戏.它编译,但不会运行.我在mac上使用netbeans,我以前从来没有这样的问题,所以我认为这是我的代码的问题:
#include <vector>
std::vector<std::vector<int> > snake;//the snake
int main(){
snake[0][0]=0;
}
Run Code Online (Sandbox Code Playgroud)
我认为它可能是2d矢量的问题.
以下是该流程图的链接:http: //i1146.photobucket.com/albums/o530/HTHVampire/C%20plus%20plus/Capture_zps5a6c3acf.jpg

这是所示流程图的代码,只是忽略流程图中的模糊语句.
#include <iostream>
using namespace std;
int main()
{
//declare and initialize a variable
int a = 0;
//prompt user for a value
cout << "please enter a value" << endl;
cin >> a;
again1:
//enter a decision block
if(a > 10)
{
if(a < 10)
{
again2:
if(a < 100)
{
a = a - 3;
goto again2;
}
else goto again1;
}
else
{
a = a - 7;
goto again1;
}
}
else …Run Code Online (Sandbox Code Playgroud) c++ ×7
c ×3
2d-vector ×1
algorithm ×1
c++11 ×1
casting ×1
constructor ×1
destructor ×1
expression ×1
foreach ×1
glsl ×1
goto ×1
if-statement ×1
inheritance ×1
ios ×1
opengl-es ×1
reflection ×1
shared-ptr ×1