Thursday, 15 April 2010

Template Classes and methods in C++ -


I am using C # for almost a year, I try to go to C ++ in Visual Studio I am here. Anyways, I am trying to create a normal binary tree in C ++ and run some compilation errors that I can not seem to fix.

The initial research class indicated the template to be placed in the header file, however

some advice would be greatly appreciated with some other advice.

Thanks

Here's the code.

  #include "stdafx.h" using namespace std; Int _tmain (int argc, _TCHAR * argv []) {tree_node & lt; Int & gt; IntTree (1, tree_node & lt; int & gt; (1), tree_node & lt; int & gt; (2)); Cout & lt; & Lt; IntTree.toString () & lt; & Lt; Endl; Return 0; } Template & lt; Class TData & gt; Class triode {Private: Teadata data; TreeNode & LT; TData & gt; & Amp; Left; TreeNode & LT; TData & gt; & Amp; right; Zero set data (tudata data) {data = data; } Public: TriNode & lt; TData & gt; (Tudata data) {set data (data); } Treeode & lt; TData & gt; (Tudata data, Triode & lt; TData & gt; Left node, Triode & lt; tidata & gt; Correct node) {Setdata (data); SetLeft (leftNode); SetRight (rightNode); } Zero set lift (TreeNode  and left node) {Left = leftNode; } Zero setwrite (treenode  & amp; rightNode) {right = rightNode; } Treeode & lt; TDTDa & gt; & Amp; GetLeft () {Return Left; } Treeode & lt; TDTDa & gt; & Amp; GetRight () {Return correct; } TDITA & amp; GetData () {Return and Data; } String to string () {return left-> ToString () + Data + Right-> ToString (); }}; Error C2228: '.toString' should be left cell / straight / union Error C2065: 'Triode': Undeclared identifier error C2065: 'IntTree': Undeclared identifier error C2062: type 'int' unexpected  
Post-text "itemprop =" text ">

At the point of use in your _tmain () TreeNode & lt; & Gt; has not been announced yet.

You must include the full template class announcement / definition before _tmain () , or better than that by adding it to a different header file.


No comments:

Post a Comment