English 中文(简体)
错误:在“boiler:uniqueInstance == 0l'
原标题:error: no match for ‘operator==’ in ‘boiler::uniqueInstance == 0l’
#include <iostream>
using namespace std;

class boiler
{
private:
    static boiler uniqueInstance;

    bool boilerEmpty;
    bool mixtureBoiled;

    boiler()
    {
        boilerEmpty = true;
        mixtureBoiled = false;
    }

public:
    static boiler getInstance()
    {
        if(uniqueInstance == NULL)
        {
            uniqueInstance = new boiler();
        }

        return uniqueInstance;
    }
};

以上法典重述标题中的错误。

anisha@linux-y3pi:~> g++ -Wall test.cpp
test.cpp: In static member function ‘static boiler boiler::getInstance()’:
test.cpp:22:26: error: no match for ‘operator==’ in ‘boiler::uniqueInstance == 0l’
test.cpp:24:34: error: no match for ‘operator=’ in ‘boiler::uniqueInstance = (operator new(2u), (<statement>, ((boiler*)<anonymous>)))’
test.cpp:5:1: note: candidate is: boiler& boiler::operator=(const boiler&)

为什么? 我们能否将“目标”与民族解放军进行比较? 是否存在一些同yn问题?

最佳回答

也许需要一点点:

static boiler* uniqueInstance;

自那时起,你开始使用<代码>新。 这里:

uniqueInstance = new boiler ();

汇编者告诉你,它无法将<编码>锅炉的事例与斜体(实际时间很长)进行比较。 这一比较没有。 点数可与整体类型相比较,后者可与0进行比较。

这里,与<代码>NUL的比较是检查贵点是否已经启动的一种手段。 在实践中如何做到这一点并不明显,不存在无效或未经推定的事例。 您可以通过界定适当的<代码>operator=而比较一个物体,但这一比较可能没有意义,因为<代码>NUL常常只是<0>的另一个名称。

问题回答

页: 1

 static boiler uniqueInstance;

but sometimes treat it as a pointer:

uniqueInstance = new boiler ();

我认为,你应当宣布它为点人,以便你能够积极分配这样的情况:

static boiler* uniqueInstance;

You ll also want to change getInstance() to return a pointer:

static boiler* getInstance() //...

Finally make sure you actually have a definition of uniqueInstance somewhere outside of the class declaration. In one spot in a .cpp file (not a header):

boiler* boiler::uniqueInstance;




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签