C ++ E0147声明与静态对象不兼容

时间:2017-09-07 14:44:03

标签: c++11

Websource.hpp

#ifndef WEBSOURCE_HPP
#define WEBSOURCE_HPP
#pragma once

class Colour
{
public:
    unsigned char _ucRed;
    unsigned char _ucGreen;
    unsigned char _ucBlue;
    Colour(unsigned char i_red, unsigned char i_green, unsigned char i_blue);
    Colour(Colour& c);
    Colour();
    void setColour(unsigned char i_red, unsigned char i_green, unsigned char i_blue);
};

Colour::Colour(unsigned char i_red, unsigned char i_green, unsigned char i_blue)
{
    this->setColour(i_red, i_green, i_blue);
}

Colour::Colour(Colour& c)
{
    this->setColour(c._ucRed, c._ucGreen, c._ucBlue);
}

Colour::Colour()
{
    this->setColour((unsigned char)0, (unsigned char)0, (unsigned char)0);
}

void Colour::setColour(unsigned char i_red, unsigned char i_green, unsigned char i_blue)
{
    this->_ucRed = i_red;
    this->_ucGreen = i_green;
    this->_ucBlue = i_blue;
}

#endif

Website.hpp

#ifndef WEBSITE_HPP
#define WEBSITE_HPP
#pragma once

#include "Websource.hpp"

template <typename T, int N = 16>
class Page {
public:
    static Colour c_logo;   // logo colour
};

Colour website::Page<double>::Page::c_logo();

#endif

此代码导致错误0147。

  

严重级代码说明项目文件行抑制状态错误   (有效)E0147声明与&#34;颜色不兼容   website :: Page :: c_logo [T = double,N = 16]&#34; (在线宣布   31   &#34; c:\ Users \ hasler \ Documents \ ga_design \ Website.hpp&#34;)ga_design c:\ Users \ hasler \ Documents \ ga_design \ Website.hpp 88

然而,使用另一个构造函数就像一个魅力:

Colour website::Page<double>::Page::c_logo(0,0,0);

我在这里努力理解为什么一个构造函数会工作而另一个构造函数不会工作。

0 个答案:

没有答案