Last active
March 21, 2016 22:29
-
-
Save mcleary/6e0684a5e5e10a4abfe7 to your computer and use it in GitHub Desktop.
Problemas com typedef
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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