g ++:'const'限定符不能应用于... [英] g++: 'const' qualifiers cannot be applied to...

查看:77
本文介绍了g ++:'const'限定符不能应用于...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计:)


这个有点搞笑......我们是四个人在同一个项目上工作,

大家在Linux上使用KDevelop和g ++。我们三个人正在使用Mandrake,

与g ++ 3.4.3和3.4.1。项目在这三个计算机上很好地编译。


在第四台计算机上,使用KDevelop运行SUSE 9.3,但g ++ 3.3.5,

和学校'Debian服务器(实际上是最终编译代码的b $ b)服务器,也运行g ++ 3.3.5,我们得到一系列的

''const''限定符不能应用于...编译时出错。


这是导致错误的类的.h文件的开头。

错误是指最后一行,即构造函数声明:


< code snippet>


#ifndef STDFILEMGR_H

#define STDFILEMGR_H

#include< dirent.h>

#include< fcntl.h>

#include< string>

#include" reporterfunctiontype.typedef"


命名空间std

{

类FileManager

{

public:

FileManager(const string& root_,int bufferSize_ ,const

reporterFunctionType * reporter_);


< / code snippet>


和错误(对第31行的引用实际上是上面的FileManager ...

行,我没有在此处的.h文件顶部添加评论。


<错误>


g ++ -c filemanager.cpp

filemanager.cpp中包含的文件:12:

filemanager.h:31:错误:`const''qualif iers不能应用于`void(

(const

std :: string&)''

filemanager.cpp:18:错误: `const''限定符不能应用于`void

()(const std :: string&)''

make:*** [filemanager.o]错误1


< / error>

这个版本的g ++编译器这是一个已知问题吗?或者只是

我们做一些愚蠢的事情,新版本的g ++编译器接受

,即使它不正确吗?


TIA,

丹尼尔:)

-

为什么猫跳出窗户?因为那里有爱!

解决方案

DanielESFA写道:

这是一个已知的问题使用这个版本的g ++编译器?或者只是我们做了一些愚蠢的事情,即使新版本的g ++编译器接受它是不正确的?




我们正在做一些不正确的事情。它是

函数指针上的const。没问题了,抱歉;)


干杯,

丹尼尔:)


-

为什么猫跳出窗户?因为那里有爱!


DanielESFA< so ********* @ il.i.get.viruses.and.spam>写在

新闻:42 *********************** @ news.sunsite.dk:

嘿家伙:)

这个有点搞笑......我们是四个人在同一个项目上工作,每个人都使用KDevelop和g ++ Linux操作系统。我们三个人使用Mandrake,使用g ++ 3.4.3和3.4.1。项目很好地汇编了这三台计算机。

在第四台计算机上,使用KDevelop运行SUSE 9.3,但是g ++
3.3.5,以及学校的Debian服务器(最终会实际编译代码的那个),也运行g ++ 3.3.5,我们得到一系列'const''限定符不能应用于..."错误
编译时。

这是导致错误的类的.h文件的开头。
错误引用最后一行,即构造函数声明:

<代码片段>

#ifndef STDFILEMGR_H
#define STDFILEMGR_H

#include< dirent.h>
#include< fcntl.h>
#include< string>
#include" reporterfunctiontype.typedef"

命名空间std
{
class FileManager
公开:
FileManager(const string& root_,int bufferSize _,
const
reporterFunctionType * reporter_);

< / code snippet>




呃..你不应该在std命名空间中添加任何内容....


Andre Kostur写道:

DanielESFA< so ********* @ il.i.get.viruses.and.spam>在
新闻中写道:42 *********************** @ news.sunsite.dk:

嘿家伙:)

这是一个有趣的...我们是四个人在同一个项目上工作,每个人都在Linux上使用KDevelop和g ++。我们三个人使用Mandrake,使用g ++ 3.4.3和3.4.1。项目很好地汇编了这三台计算机。

在第四台计算机上,使用KDevelop运行SUSE 9.3,但是g ++
3.3.5,以及学校的Debian服务器(最终会实际编译代码的那个),也运行g ++ 3.3.5,我们得到一系列'const''限定符不能应用于..."错误
编译时。

这是导致错误的类的.h文件的开头。
错误引用最后一行,即构造函数声明:

<代码片段>

#ifndef STDFILEMGR_H
#define STDFILEMGR_H

#include< dirent.h>
#include< fcntl.h>
#include< string>
#include" reporterfunctiontype.typedef"

命名空间std
{
class FileManager
公开:
FileManager(const string& root_,int bufferSize _,
const
reporterFunctionType * reporter_);

< / code snippet>



呃..你不应该在std命名空间中添加任何内容....



LOL:D原谅我笑,但没有它,你必须在你引用的任何内容前加上std ::"

! :)

-

为什么猫跳出窗户?因为那里有爱!


Hey guys :)

This is a bit of a funny one... We''re four guys working on the same project,
everybody using KDevelop and g++ on Linux. Three of us are using Mandrake,
with g++ 3.4.3 and 3.4.1. Project compiles nicely on these three puters.

On the fourth computer, running SUSE 9.3 using KDevelop also, but g++ 3.3.5,
and on the school''s Debian server (which is the one that''ll actually be
compiling the code eventually), also running g++ 3.3.5, we get a series of
"''const'' qualifiers cannot be applied to..." errors when compiling.

This is the start of the .h file of the class that causes the error. The
error refers to the last line, i.e. the constructor declaration:

<code snippet>

#ifndef STDFILEMGR_H
#define STDFILEMGR_H

#include <dirent.h>
#include <fcntl.h>
#include <string>
#include "reporterfunctiontype.typedef"

namespace std
{
class FileManager
{
public:
FileManager(const string &root_, int bufferSize_, const
reporterFunctionType* reporter_);

</code snippet>

And the error (the reference to line 31 is actually the "FileManager..."
line above, I''ve not included the comment at the top of the .h file here)

<error>

g++ -c filemanager.cpp
In file included from filemanager.cpp:12:
filemanager.h:31: error: `const'' qualifiers cannot be applied to `void (
(const
std::string&)''
filemanager.cpp:18: error: `const'' qualifiers cannot be applied to `void
()(const std::string&)''
make: *** [filemanager.o] Error 1

</error>

Is this a known problem with this version of the g++ compiler? Or is it just
us doing something silly that the newer version of the g++ compiler accepts
even though it''s not correct?

TIA,
Daniel :)
--
Why do cats jump out of windows? Because there''s love out there!

解决方案

DanielESFA wrote:

Is this a known problem with this version of the g++ compiler? Or is it
just us doing something silly that the newer version of the g++ compiler
accepts even though it''s not correct?



It''s us doing something that''s not "correct". It was the const on the
function pointer that did it. No problem anymore, sorry ;)

Cheers,
Daniel :)

--
Why do cats jump out of windows? Because there''s love out there!


DanielESFA <so*********@il.i.get.viruses.and.spam> wrote in
news:42***********************@news.sunsite.dk:

Hey guys :)

This is a bit of a funny one... We''re four guys working on the same
project, everybody using KDevelop and g++ on Linux. Three of us are
using Mandrake, with g++ 3.4.3 and 3.4.1. Project compiles nicely on
these three puters.

On the fourth computer, running SUSE 9.3 using KDevelop also, but g++
3.3.5, and on the school''s Debian server (which is the one that''ll
actually be compiling the code eventually), also running g++ 3.3.5, we
get a series of "''const'' qualifiers cannot be applied to..." errors
when compiling.

This is the start of the .h file of the class that causes the error.
The error refers to the last line, i.e. the constructor declaration:

<code snippet>

#ifndef STDFILEMGR_H
#define STDFILEMGR_H

#include <dirent.h>
#include <fcntl.h>
#include <string>
#include "reporterfunctiontype.typedef"

namespace std
{
class FileManager
{
public:
FileManager(const string &root_, int bufferSize_,
const
reporterFunctionType* reporter_);

</code snippet>



Uh.. you''re not supposed to be adding anything to the std namespace....


Andre Kostur wrote:

DanielESFA <so*********@il.i.get.viruses.and.spam> wrote in
news:42***********************@news.sunsite.dk:

Hey guys :)

This is a bit of a funny one... We''re four guys working on the same
project, everybody using KDevelop and g++ on Linux. Three of us are
using Mandrake, with g++ 3.4.3 and 3.4.1. Project compiles nicely on
these three puters.

On the fourth computer, running SUSE 9.3 using KDevelop also, but g++
3.3.5, and on the school''s Debian server (which is the one that''ll
actually be compiling the code eventually), also running g++ 3.3.5, we
get a series of "''const'' qualifiers cannot be applied to..." errors
when compiling.

This is the start of the .h file of the class that causes the error.
The error refers to the last line, i.e. the constructor declaration:

<code snippet>

#ifndef STDFILEMGR_H
#define STDFILEMGR_H

#include <dirent.h>
#include <fcntl.h>
#include <string>
#include "reporterfunctiontype.typedef"

namespace std
{
class FileManager
{
public:
FileManager(const string &root_, int bufferSize_,
const
reporterFunctionType* reporter_);

</code snippet>



Uh.. you''re not supposed to be adding anything to the std namespace....



LOL :D Forgive me for laughing, but without it you''d have to prepend "std::"
to just about anything you reference! :)
--
Why do cats jump out of windows? Because there''s love out there!


这篇关于g ++:'const'限定符不能应用于...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆