C ++ LNK2001未解析的带有静态类的外部符号

时间:2017-09-04 12:40:40

标签: c++

我一直在读这几个类似的线程,但它只是在我脑海中。我有一个类Page,其中包含一个静态类Color,它应该被类Page的每个实例使用(我不想在每次创建页面时重新计算这种颜色)

  

严重级代码描述项目文件行抑制状态   错误LNK2001未解析的外部符号“public:static class Color website :: Page :: c_logo”(?c_logo @?$ Page @ N $ 0BA @@ website @@ 2VColour @@ A)ga_design C:\ Users \ hasler \ Documents_project \ ga_design \ ga_design \ ga_design.obj 1

Website.hpp

#ifndef WEBSITE_HPP
#define WEBSITE_HPP
#pragma once

#include "src\CTML.hpp"

[...]

class Colour
{
private:
    unsigned char _ucRed;
    unsigned char _ucGreen;
    unsigned char _ucBlue;
public:
    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)
{
    Colour(c._ucRed, c._ucGreen, c._ucBlue);
}

Colour::Colour()
{
    Colour(0, 0, 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;
}

[...]

namespace website 
{

template <typename T, int N = 16>
class Page {
private:
    Document doc;                       // CTML document
    std::vector<T> param;               // estimated parameter(s)
    double value;                       // calculated value of website
    Colour c_back;                      // background colour
    void calculateValue();

public:
    static Colour c_logo;                   // logo colour
    Page(const std::vector<T>& x);          // constructor              
    double getValue(){  return value;   }   // return calculated value
    bool createDoc(unsigned int geno);      // create and save html file
};

ga_design.cpp

#include "stdafx.h"
#include "src\Galgo.hpp"
#include "src\CTML.hpp"
#include "Website.hpp"

[...]

int main()
{
    website::Page<double>::c_logo = Colour(50, 150, 250);

    [...]
}

是吗,因为c_logo的定义在main()中而不是在相应的cpp文件中?

0 个答案:

没有答案