Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

lost arguments

47 views
Skip to first unread message

Popping mad

unread,
Nov 8, 2016, 4:16:09 PM11/8/16
to
/*
* =====================================================================================
*
* Filename: nodes.h
*
* Description: description of phylogentic nodes as per
* Fitch and Sannkoff as describd by Felenstein
*
* Version: 1.0
* Created: Nov 4 21:15:49 EDT 2016
* Revision: none
* Compiler: gcc
*
* Author: Ruben Safir,
* Company: LIU Thesis
*
* =====================================================================================
*/
#ifndef NODES_H
#define NODES_H
#include<iostream>
#include<string>
#include<vector>
namespace tree {


/* ==============================================================================
* Class NODE -
* Description - This is a node in the tree that must undergo parsimony evaluation
* ================================================================================
*/
template<class unk>
class NODE{
public:
//=========================LIFECYCLE=========================================
/* Constructor */
NODE( std::string xt, const unk &x , NODE<unk> *xcl= 0, NODE<unk> *xcr = 0, NODE<unk> *xp = 0 );
//NODE( std::string xt, unk &x , NODE<unk> *xcl= 0, NODE<unk> *xcr = 0, NODE<unk> *xp = 0 );
~NODE();

/* ==================== ACCESSORS ======================================= */
//no need for inline when you are defineing functions within the class definition
std::string trait()const{
return _trait;
}
unk states()const{
return _states;
};
NODE<unk> * cl()const{
return _cl;
};
NODE<unk> * cr()const{
return _cr;
};
NODE<unk> * p()const{
return _p;
};
void states(const unk &x){
_states = x;
}
void trait(std::string xt){
_trait = xt; //With genetics this is a A C G T although it is just a label
}
void cl(NODE<unk> *xcl){ //This is the left child node in the tree
_cl = xcl;
}
void cr(NODE<unk> *xcr){//This is the right node child node in the tree
_cr = xcr;
}
void p(NODE<unk> *xp){//This is the parent node in the tree
_p = xp;
}
/* ==================== MUTATORS ======================================= */

/* ==================== OPERATORS ======================================= */
//void display();
template <class T>
friend std::ostream& operator<<(std::ostream& os, const T&);

template<class T>
friend std::ostream& operator<<(std::ostream& os, const NODE<T> &);

protected:
/* ==================== DATA MEMBERS ======================================= */


private:
/* ==================== DATA MEMBERS ======================================= */
std::string _trait;
unk _states;
NODE<unk> * _cl, * _cr, * _p;


}; /* ----- end of template class NODE ----- */

template<class unk>
std::ostream& operator<<(std::ostream& os, const NODE<unk>& vec){

for( auto& y : vec.state() )
os << y << std::endl;
return os;
}

template<class unk>
NODE<unk>::NODE( std::string xt, const unk &x, NODE<unk> *xcl , NODE<unk> *xcr, NODE<unk> *xp ){
states(x);
trait(xt);
cl(xcl);
cr(xcr);
p(xp);
std::cout << trait() << " node " << "has the following states => " << std::endl;
}

//template<class unk>
//NODE<unk>::NODE( std::string xt, unk &x, NODE<unk> *xcl , NODE<unk> *xcr, NODE<unk> *xp ){
// states(x);
// trait(xt);
// cl(xcl);
// cr(xcr);
// p(xp);
// std::cout << trait() << " node " << "has the following states => " << std::endl;
//}


template<class unk>
tree::NODE<unk>::~NODE<unk>(){
}

/*
* =====================================================================================
* Class: State
* Description: This describes a possible individual state or charactoristic
* =====================================================================================
*/
template<class cost>
class state
{
public:
/* ==================== LIFECYCLE ======================================= */
/* constructor */
//r is the minimum cost of a single state when compared to the child nodes
explicit state<cost>(std::string const xa, cost xr)
:_nam{xa}, _r{xr}
{
std::cout << "Building a state pair" << std::endl;
std::cout << "nam => " << nam() << "\tcost=> " << r() << std::endl;
};


/* ==================== ACCESSORS ======================================= */
std::string nam(){return _nam;};
cost r(){return _r;};
void r(cost b ){_r = b;};
/* ==================== MUTATORS ======================================= */

/* ==================== OPERATORS ======================================= */

/* ==================== DATA MEMBERS ======================================= */
protected:

private:
std::string _nam;
cost _r;

}; /* ----- end of class State ----- */

/*
* =====================================================================================
* Class: Pstates
* Description: vector of all possible states
* =====================================================================================
*/
template<class cost>
class Pstates
{
public:

/* ==================== LIFECYCLE ======================================= */
/* constructor */
Pstates (std::vector< state<cost> > x)
: _vstate{x}
{
for( auto& y : _vstate)
std::cout << y << std::endl;
};

// Pstates()
// : _vstate{0}
// {};

~Pstates (){}; /* destructor */

/* ==================== ACCESSORS ======================================= */
const std::vector< state<cost> >& vstate(){
return _vstate;
}
void vstate(std::vector< state<cost> > in ){
_vstate = in;
}

/* ==================== MUTATORS ======================================= */

/* ==================== OPERATORS ======================================= */

const Pstates& operator = ( const Pstates &other ); /* assignment operator */




/* ==================== DATA MEMBERS ======================================= */
protected:

private:
std::vector< state <cost> > _vstate;

}; /* ----- end of class Pstates ----- */

/* Overload ostream function */
template <class outcost>
std::ostream& operator << ( std::ostream &output, state<outcost> &p )
{
output << "nam => " << p.nam() << "\tcost=> " << p.r() << std::endl;
return output;
}

/*


template<class unk>
inline unk NODE<unk>::value(){ if(this != NULL) return _value; else return NULL; };

template<class unk>
inline void NODE<unk>::value(unk val){
_value = val;
};

*/


/*
template<class unk>
class LIST{
public:
LIST<unk>() : _at_front(0), _at_end(0), _size(0) {}
inline int size();
inline void insert(NODE<unk> *, unk);
inline void insert(unk);
inline void front(unk);
inline void up_size();
inline void down_size();
void display(ostream &os = cout);
void remove_front();
void remove_all();
void remove_item(unk);
void remove_item(NODE<unk> *);
NODE<unk> * find(unk);
NODE<unk> * find_all(unk, NODE<unk> * last = NULL );

~LIST<unk>();

private:
NODE<unk> *_at_front;
NODE<unk> *_at_end;
int _size;
LIST<unk>(const LIST<unk>&);
LIST<unk>& operator=( const LIST<unk>&);
};
*/

/*
template<class unk>
void LIST<unk>::display(ostream &os){
NODE<unk> * tmp = _at_front;

if (tmp == 0){
os << "No List" << endl;
return;
}


//unk i =0;
while(tmp != _at_end){
//cout << "Entering While Loop: "<< ++i << endl;
os << tmp->value() << ":";
tmp = tmp->next();
}

os << tmp->value() << endl;

}
*/
} /*---End of Namespace TREE---*/
#endif


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#include<cstdlib>
#include <iostream>
#include "nodes.h"
using namespace std;

int main(int argv, char ** argc)
{
tree::state<int> a{"A", 65500};
tree::state<int> c{"C", 0};
tree::state<int> g{"G", 65500};
tree::state<int> t{"T", 65500};

vector< tree::state<int> > posible_states = {a,c,g,t};

tree::Pstates<int> node_status{posible_states};
tree::NODE<int> cr1{"T01", 3};
tree::NODE<int> cl1{"T00",2};
// tree::NODE<int> root{"T0",1};

// tree::NODE<Pstates<int> > cr1{"T01", 3};
// tree::NODE<Pstates<int> > cl1{"T00",2};
tree::NODE<tree::Pstates<int> > root{"T0",node_status};
return 0;
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
when this compiles and reaches the last construction it loses parameters


|| g++ -Wall -ggdb -c nodes.cpp
|| g++ -Wall -ggdb -o fitch.o -c fitch.cpp
|| nodes.h: In instantiation of ‘tree::NODE<unk>::NODE(std::__cxx11::string, const unk&, tree::NODE<unk>*, tree::NODE<unk>*, tree::NODE<unk>*) [with unk = tree::Pstates<int>; std::__cxx11::string = std::__cxx11::basic_string<char>]’:
fitch.cpp|22 col 55| required from here
nodes.h|105 col 96| error: no matching function for call to ‘tree::Pstates<int>::Pstates()’
|| NODE<unk>::NODE( std::string xt, const unk &x, NODE<unk> *xcl , NODE<unk> *xcr, NODE<unk> *xp ){
|| ^
nodes.h|180 col 3| note: candidate: tree::Pstates<cost>::Pstates(std::vector<tree::state<cost> >) [with cost = int]
|| Pstates (std::vector< state<cost> > x)
|| ^~~~~~~
nodes.h|180 col 3| note: candidate expects 1 argument, 0 provided
nodes.h|174 col 7| note: candidate: tree::Pstates<int>::Pstates(const tree::Pstates<int>&)
|| class Pstates
|| ^~~~~~~
nodes.h|174 col 7| note: candidate expects 1 argument, 0 provided
make: *** [makefile|10| fitch.o] Error 1

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

specifically right here...
fitch.cpp|22 col 55| required from here
nodes.h|105 col 96| error: no matching function for call to ‘tree::Pstates<int>::Pstates()’
|| NODE<unk>::NODE( std::string xt, const unk &x, NODE<unk> *xcl , NODE<unk> *xcr, NODE<unk> *xp ){


template<class unk>
NODE<unk>::NODE( std::string xt, const unk &x, NODE<unk> *xcl , NODE<unk> *xcr, NODE<unk> *xp ){
states(x);
trait(xt);
cl(xcl);
cr(xcr);
p(xp);
std::cout << trait() << " node " << "has the following states => " << std::endl;
}

it is not supposed to call Pstates<int>::Pstates()

I'm specifically sending the argument by reference. It is not supposed to be constructing a thing.

red floyd

unread,
Nov 9, 2016, 2:22:57 AM11/9/16
to
On 11/8/2016 1:15 PM, Popping mad wrote:

> template<class unk>
> NODE<unk>::NODE( std::string xt, const unk &x, NODE<unk> *xcl , NODE<unk> *xcr, NODE<unk> *xp ){
> states(x);
> trait(xt);
> cl(xcl);
> cr(xcr);
> p(xp);
> std::cout << trait() << " node " << "has the following states => " << std::endl;
> }
>]
Your syntax is off. Look up the syntax for initializer lists.


Öö Tiib

unread,
Nov 9, 2016, 4:58:55 AM11/9/16
to
On Tuesday, 8 November 2016 23:16:09 UTC+2, Popping mad wrote:
>
> it is not supposed to call Pstates<int>::Pstates()
>
> I'm specifically sending the argument by reference. It is not supposed to be constructing a thing.

The compiler did not complain about that argument. It
did complain that it knows no implicit ways how to
construct '_states' member *before* your idiotic code
tries to assign x to it in that 'states(x)' method call.

Popping mad

unread,
Nov 9, 2016, 10:41:45 AM11/9/16
to
I love it when people are really nasty in tech forums. Tom Christiansen,
back in the day, he was the best. He might have been single handly
responsible for the Guido writing python.

I do thank you for the tip though.

red floyd

unread,
Nov 10, 2016, 4:47:46 PM11/10/16
to
Further hint. Move the initializer list OUTSIDE the braces, thus


template<class unk>
NODE<unk>::NODE( std::string xt, const unk &x, NODE<unk> *xcl ,
NODE<unk> *xcr, NODE<unk> *xp ) :
states(x),
trait(xt),
cl(xcl),
cr(xcr),
0 new messages