相关疑难解决方法(0)

在此类声明中声明一个类的实例并就地初始化它

这就是我现在拥有的:

class CColorf
{
public:
    CColorf();
    CColorf(float r, float g, float b, float a = 1.0f);

public:
    float r, g, b, a;

// predefined colors
    // rgb(0.0, 0.0, 1.0)
    static const CColorf blue;
};
Run Code Online (Sandbox Code Playgroud)

它适用blue于ccolorf.cpp中的定义,如下所示:

CColorf const CColorf::blue = CColorf(0.0f, 0.0f, 1.0f);
Run Code Online (Sandbox Code Playgroud)

这就是我想做的事情:

class CColorf
{
    ...

// predefined colors
    // rgb(0.0, 0.0, 1.0)
    static const CColorf blue = CColorf(0.0f, 0.0f, 1.0f);
};
Run Code Online (Sandbox Code Playgroud)

但它会产生编译错误:

具有类内初始化程序的静态数据成员必须具有非易失性const整数类型

有没有办法避免在这里需要单独的声明和定义?

c++ c++11

5
推荐指数
1
解决办法
133
查看次数

不完整的类型

我为'next'和'previous'变量得到了一个不完整的类型错误.我不确定我做错了什么,因为我在用C++编写类时非常生疏.任何帮助,将不胜感激!谢谢.

#include<iostream>

using namespace std;

class LinearNode
{
    public:
        //Constructor for the LinearNode class that takes no arguments 
        LinearNode();
        //Constructor for the LinearNode class that takes the element as an argument
        LinearNode(int el);
        //returns the next node in the set.
        LinearNode getNext();
        //returns the previous node in the set
        LinearNode getPrevious();
        //sets the next element in the set
        void setNext(LinearNode node);
        //sets the previous element in the set
        void setPrevious(LinearNode node);
        //sets the element of the node
        void setElement(int el); …
Run Code Online (Sandbox Code Playgroud)

c++ incomplete-type

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

C++ 错误:字段类型不完整 - 声明它是自己的类对象

我是 C++ 编程的新手。这是我的代码:

#ifndef NODE_H
#define NODE_H    

class Node
{
    public:
        Node();
        Node(int);
        virtual ~Node();
        Node(const Node& other);

        int getValue() { return value; }
        void setValue(int val) { value = val; }
        Node getPrev() { return prev; }
        void setPrev(Node val) { prev = val; }
        Node getNext() { return next; }
        void setNext(Node val) { next = val; }

    private:
        int value; //!< Member variable "value"
        Node prev; //!< Member variable "prev"
        Node next; //!< Member variable "next"
}; …
Run Code Online (Sandbox Code Playgroud)

c++

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

什么时候在C ++中发生不完整的类型错误

谁能告诉我C ++编译器何时引发“不完整的类型错误”?

注意:我故意将这个问题留给了一些开放的答案,以便我自己调试代码。

c++ incomplete-type

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

标识符"xxx"未定义,类指针和结构

我正在编写一个包含与以下类似结构的小型c ++程序:

class A {
   B * someObjects;
};

typedef A* APointer;

struct B{
   APointer a;
   int n;
}
Run Code Online (Sandbox Code Playgroud)

尝试编译这会给出"标识符未定义"错误,因为结构B在类A中是未知的.否则在类A之前声明结构B应该仍然给出类似的错误,因为那时B不知道APointer,或者APointer不知道A有没有可能让A级和B级成为好朋友?提前致谢!

c++ struct pointers typedef class

0
推荐指数
1
解决办法
2105
查看次数

字段'指针'具有不完整类型'节点'

我正在尝试创建一个新的Node cpp/h文件,但是我收到以下错误:

字段'指针'具有不完整类型'节点'

头文件

#ifndef NODE_HEADER
#define NODE_HEADER

template <class T>
class Node {
    private:
        T value;
        Node<T> pointer; //The problem seems to be here
    public:
        Node<T>();
        Node<T>(T value);
        Node<T>(T value, Node<T> pointer);
        T get_value();
        void set_value(T value);
        Node<T> get_pointer();
        void set_pointer(Node<T> pointer);
};

#endif
Run Code Online (Sandbox Code Playgroud)

c++ header-files

-1
推荐指数
1
解决办法
618
查看次数

标签 统计

c++ ×6

incomplete-type ×2

c++11 ×1

class ×1

header-files ×1

pointers ×1

struct ×1

typedef ×1