C++ Tree node ,when g++ compile multiple cpp files should list them respectively

//TreeNode.h
#include <iostream>
using namespace std;

class TreeNode
{
public:
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode *NewTreeNode(int keyValue);
    void treeNode7();
};
//TreeNode.cpp
#include "TreeNode.h"
TreeNode* TreeNode::NewTreeNode(int keyValue)
{           
    //Create a new node
    TreeNode *node=new TreeNode;

    //assign a value
    node->val=keyValue;

    //Initialize Left and Right pointer
    node->left=NULL;
    node->right=NULL;
    return node;
}

void TreeNode::treeNode7()
{
    TreeNode *root=NewTreeNode(1);
    root->left=NewTreeNode(2);
    root->right=NewTreeNode(3);
    root->left->left=NewTreeNode(4);
    root->left->right=NewTreeNode(5);
    root->right->left=NewTreeNode(6);
    root->right->right=NewTreeNode(7);

    cout<<"root->val="<<root->val<<endl;
    cout<<"root->left->val="<<root->left->val<<endl;
    cout<<"root->left->left->val="<<root->left->left->val<<endl;
    cout<<"root->left->right->val="<<root->left->right->val<<endl;
    cout<<"root->right->left->val="<<root->right->left->val<<endl;
    cout<<"root->right->right->val"<<root->right->right->val<<endl;
}
 

Compile via

g++ -g -std=c++2a -I. h1.cpp TreeNode.cpp -o h1 -luuid

When compile multiple cpp files ,please add them respectively in the command as above  

Run ./h1

C++ Tree node ,when g++ compile multiple cpp files should list them respectively

 

原文链接: https://www.cnblogs.com/Fred1987/p/15781295.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;

也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬

    C++ Tree node ,when g++ compile multiple cpp files should list them respectively

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/401628

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年4月19日 上午9:19
下一篇 2023年4月19日 上午9:19

相关推荐