Skip to content

Instantly share code, notes, and snippets.

@mcleary
Last active March 21, 2016 22:29
Show Gist options
  • Save mcleary/6e0684a5e5e10a4abfe7 to your computer and use it in GitHub Desktop.
Save mcleary/6e0684a5e5e10a4abfe7 to your computer and use it in GitHub Desktop.
Problemas com typedef
#include "graph.h"
Node::Node(int f1, int f2)
{
field1 = f1;
field2 = f2;
next = 0;
}
Node::~Node()
{
if(next)
{
delete next;
}
}
void Node::setNext(Node *node)
{
next = node;
}
std::ostream& operator<<(std::ostream &out, Node& node)
{
out << node.field1 << ":" << node.field2;
return out;
}
#ifndef GRAPH_H
#define GRAPH_H
#include <ostream>
class Node
{
public:
Node(int f1, int f2);
~Node();
void setNext(Node* node);
friend std::ostream& operator<< (std::ostream& out, Node& node);
private:
int field1;
int field2;
Node* next;
};
#endif // GRAPH_H
#include <iostream>
#include "graph.h"
int main()
{
Node* node = new Node(10, 20);
std::cout << *node << std::endl;
Node n1(20, 30);
n1.setNext(node);
std::cout << n1 << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment