在C++中通常用某种前缀命名成员变量来表示它们是成员变量而不是局部变量或参数.如果你来自MFC背景,你可能会使用m_foo.我myFoo偶尔也见过.
C#(或者可能只是.NET)似乎建议只使用下划线,如_foo.这是否允许C++标准?
当我编译链表的代码时,我得到了一堆未定义的引用错误.代码如下.我一直在编写这两个语句:
g++ test.cpp
Run Code Online (Sandbox Code Playgroud)
以及
g++ LinearNode.h LinearNode.cpp LinkedList.h LinkedList.cpp test.cpp
Run Code Online (Sandbox Code Playgroud)
我真的不明白为什么我会收到这些错误,因为我对C++中的类很生疏.我真的可以使用一些帮助.
LinearNode.h:
#ifndef LINEARNODE_H
#define LINEARNODE_H
#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 …Run Code Online (Sandbox Code Playgroud)