标签: compiler-errors

c ++编译错误:ISO C++禁止指针和整数之间的比较

我正在尝试Bjarne Stroustrup的C++书籍第三版.在实现一个相当简单的函数时,我得到以下编译时错误:

error: ISO C++ forbids comparison between pointer and integer
Run Code Online (Sandbox Code Playgroud)

可能是什么导致了这个?这是代码.错误在于if:

#include <iostream>
#include <string>
using namespace std;
bool accept()
{
    cout << "Do you want to proceed (y or n)?\n";
    char answer;
    cin >> answer;
    if (answer == "y") return true;
    return false;
}
Run Code Online (Sandbox Code Playgroud)

谢谢!

c++ compiler-errors

27
推荐指数
3
解决办法
11万
查看次数

在类中使用OpenGL glutDisplayFunc

我已经创建了一个C++类(myPixmap)来封装OpenGL GLUT工具包执行的工作.display()该类的成员函数包含设置GLUT所需的大部分代码.


void myPixmap::display()
{
    // open an OpenGL window if it hasn't already been opened
    if (!openedWindow)
    {
        // command-line arguments to appease glut
        char *argv[] = {"myPixmap"};
        int argc = 1;
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
        glutInitWindowSize(640, 480);
        glutInitWindowPosition(30, 30);
        glutCreateWindow("Experiment");
        glutDisplayFunc(draw);
        glClearColor(0.9f, 0.9f, 0.9f, 0.0);
        glClear(GL_COLOR_BUFFER_BIT);
        glutMainLoop();

        openedWindow = true;
    }  
}
Run Code Online (Sandbox Code Playgroud)

传递给的显示函数glutDisplayFunc()是该类的另一个成员函数:


void myPixmap::draw(void)
{
    glDrawPixels( m,n,GL_RGB,GL_UNSIGNED_BYTE, pixel );
}
Run Code Online (Sandbox Code Playgroud)

但是,Mac OS X 10.6.4上的gcc 4.2.1拒绝编译此代码,声称:

argument of type 'void (myPixmap::)()' …

c++ opengl compiler-errors class

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

包与Java 9中的自动模块冲突

随着Java 9的出现,我认为将我的一些项目移植到Java 9是一个很好的学习练习.在我的一个项目中,我有rxjavarxjavafx的依赖

dependencies {
    compile 'io.reactivex:rxjava:1.2.6'
    compile 'io.reactivex:rxjavafx:1.0.0'
    ...
}
Run Code Online (Sandbox Code Playgroud)

我想将此项目创建为命名模块.要做到这一点,我需要创建一个module-info.java文件,我需要指定的要求rxjava,并rxjavafx在这里.但是,这些库还没有任何模块信息.

为了解决这个问题,我读过我需要创建自动模块.根据我的理解,我需要重命名rxjavarxjavafx罐子有一个简单的名称,然后列出--module-path参数中的罐子.然后requiresmodule-info.java在jar中添加一个指令.

module com.foo.bar {
    requires rxjavafx;
    requires rxjava;
}
Run Code Online (Sandbox Code Playgroud)

我编写了一个gradle任务来为我编辑jar名称,它似乎在大多数情况下都有效.它需要编译所有的jar并将它们重命名为不包含version-info或slashes.然后将这些文件连接成一个:单独的字符串:

tasks.withType(JavaCompile) {
    delete { delete '/tmp/gradle' }
    copy {
        from configurations.compile + configurations.testCompile
        into '/tmp/gradle'
        rename '(.*)-[0-9]+\\..*.jar', '$1.jar'
        rename { String fileName -> fileName.replace("-", "") }
    }
    options.compilerArgs += ['--module-path', fileTree(dir: '/tmp/gradle', include: …
Run Code Online (Sandbox Code Playgroud)

java compiler-errors java-platform-module-system java-9

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

为什么编译器声明没有唯一的最大实例存在?

我有以下课程:

public class Obj<T> extends BaseModel {

    public static final String OBJECT = "object";

    public Obj(T object) {
        setObject(object);
    }

    public T getObject() {
        return get(OBJECT);
    }

    public void setObject(T object) {
        set(OBJECT, object);
    }
}
Run Code Online (Sandbox Code Playgroud)

和...

/** This is a 3rd party library class **/
public class BaseModel implements ModelData, Serializable {
  //...members and stuff...

  @SuppressWarnings({"unchecked", "rawtypes"})
  public <X> X get(String property) {
    X obj = null;
    if (start > -1 && end > -1) {
      Object o = …
Run Code Online (Sandbox Code Playgroud)

java compiler-construction generics compiler-errors javac

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

"未在此范围内声明"模板和继承错误

这是代码示例,它可以重现我的问题:

template <typename myType>
class Base {
public:
    Base() {}
    virtual ~Base() {}
protected:
    int myOption;
    virtual void set() = 0;
};

template <typename InterfaceType>
class ChildClass : public Base < std::vector<InterfaceType> >
{
public:
    ChildClass() {}
    virtual ~ChildClass() {}
 protected:
    virtual void set();
};

template <typename InterfaceType>
void ChildClass<InterfaceType>::set()
{
     myOption = 10;
}
Run Code Online (Sandbox Code Playgroud)

我的用法main():

ChildClass<int> myObject;
Run Code Online (Sandbox Code Playgroud)

我收到以下错误(ubuntu上的gcc 4.4.3):

'myOption'未在此范围内声明

如果我的ChildClass没有新的模板参数,这将工作正常,即:

class ChildClass : public Base < std::vector<SomeConcreteType> >
Run Code Online (Sandbox Code Playgroud)

编辑

如果我的set方法如下所示,我已设法解决它:

Base<std::vector<InterfaceType> >::myOption = 10;
Run Code Online (Sandbox Code Playgroud)

它工作正常.尽管不确定为什么我需要指定所有模板参数.

c++ inheritance templates compiler-errors g++

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

内联函数和静态内联函数之间的区别

任何人都可以告诉我内联函数和静态内联函数之间的区别是什么?

在哪些情况下,我更喜欢静态内联而不是内联?

我问这个问题,因为我有一个内联函数,我在链接(relocation error:... symbol has been discarded with discarded section ...)期间遇到编译问题.我使它成为一个正常的功能,它工作.现在我的一些老人告诉我尝试使用静态内联.以下是我的功能:

inline void wizSendNotifier (const char* nn_name, bpDU* arg=0, int aspect = -1)
{
   wizuiNotifier* notifier = ::wizNtrKit.getNotifier (nn_name);
   notifier->notify (arg, aspect);
}
Run Code Online (Sandbox Code Playgroud)

而这不是在课堂上.这是在头文件中!

我想对静态函数的调用只能在定义它的特定TU中完成.

由于我的函数是在头文件中,并且如果我将其设置为静态,是否会出现这样的情况:在哪里我包含该头文件,静态函数可以用于该翻译单元?

c++ static solaris compiler-errors inline

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

使用未声明的标识符'true'

为什么我收到此错误:

infinite.c:5:12: error: use of undeclared identifier 'true'
    while (true) {

1 error generated.
make: *** [infinite] Error 1
Run Code Online (Sandbox Code Playgroud)

...当我尝试为无限循环编译这个简单的代码时?

#include <stdio.h>

int main(void) {
    int x = 0;
    while (true) {
        printf("%i\n", x);
    }
}
Run Code Online (Sandbox Code Playgroud)

c compiler-errors

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

为什么Java增量运算符允许在没有显式转换的情况下缩小操作?

可能重复:
Java + =运算符

在Java中,这是无效的(不编译),如预期的那样:

long lng = 0xffffffffffffL;
int i;
i = 5 + lng;    //"error: possible loss of magnitude"
Run Code Online (Sandbox Code Playgroud)

但这很好(?!)

long lng = 0xffffffffffffL;
int i = 5;
i += lng;       //compiles just fine
Run Code Online (Sandbox Code Playgroud)

这显然是一个缩小的操作,可能超出int范围.那么编译器为什么不抱怨呢?

java precision compiler-errors

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

找到Xcode 4.5.2错误但Build标记为Succeeded

这个问题非常类似于:Xcode 4 Preview 4显示"Build Succeeded"但有错误

链接中提出的不同解决方案不起作用.我尝试使用产品清理,删除派生数据,重启XCode和Mac,但问题仍然存在.

似乎所有错误都链接到项目的预编译头:虽然PCH工作正常并且本身没有错误,但报告的错误看起来像是找不到此特定文件的pch.有时,在构建过程中,错误会随机出现和消失.有人对此有所了解吗?

在此输入图像描述

该错误仅出现在编辑器中打开的文件中.如果我在xcode中关闭文件但保持项目打开,则根本不会报告任何错误.

xcode compiler-errors build

26
推荐指数
3
解决办法
4689
查看次数

Flutter:找到这个候选人,但参数不匹配

我正在开发一个颤振应用程序,项目运行完美,但突然项目没有运行,它给了我一个错误。

这是我尝试运行应用程序时收到的错误代码

Compiler message:
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/extended_image-0.7.2/lib/src/gesture/extended_image_slide_page_route.dart:333:9: Error: No named parameter with the name 'animation'.
        animation: animation,
        ^^^^^^^^^
/C:/flutter/packages/flutter/lib/src/cupertino/route.dart:435:3: Context: Found this candidate, but the arguments don't match.
  CupertinoFullscreenDialogTransition({
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_svg-0.15.0/lib/src/picture_stream.dart:92:3: Error: The superclass, 'Diagnosticable', has no unnamed constructor that takes no arguments.
  PictureStream();
  ^^^^^^^^^^^^^
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_svg-0.15.0/lib/src/picture_stream.dart:192:16: Error: The superclass, 'Diagnosticable', has no unnamed constructor that takes no arguments.
abstract class PictureStreamCompleter extends Diagnosticable {
               ^
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/extended_image-0.7.2/lib/src/gesture/extended_image_slide_page_route.dart:333:9: Error: No named parameter with the name 'animation'.
        animation: animation,                                           
        ^^^^^^^^^
/C:/flutter/packages/flutter/lib/src/cupertino/route.dart:435:3: Context: Found this candidate, …
Run Code Online (Sandbox Code Playgroud)

compiler-errors run-app dart flutter flutter-dependencies

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