我应该怎么做才能访问.... [英] what should i do to access ....

查看:89
本文介绍了我应该怎么做才能访问....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误C2664:``void std :: queue< _Ty> :: push(int&)'':无法将参数1从``node''转换为``int&&''
粗线最后一行

error C2664: ''void std::queue<_Ty>::push(int &&)'' : cannot convert parameter 1 from ''node'' to ''int &&''
bold line the last line

#include "StdAfx.h"
#include<string>
#include<queue>
#include<iostream>
using namespace std ;
#define ARRAY_SIZE 20

class node
{
public:
	int weight ;
    char value;
	const node *child0;
	const node *child1;

	node( char c = 0, int i = -1 ) 
	{
		value = c;
		weight = i;
		child0 = 0;
		child1 = 0;
	}

	node( const node* c0, const node *c1 ) 
	{
		value = 0;
		weight = c0->weight + c1->weight;
		child0 = c0;
		child1 = c1;
	}

		bool operator<( const node &a ) const {
		return weight <a.weight;
	}
  void traverse(string code="") const
	{
		
	if ( child0 )
	{
		child0->traverse( code + ''0'' );
		child1->traverse( code + ''1'' );
	} 
	else
	{
		cout <<" " <<value <<"	  ";
		cout <<weight;
		cout <<"	 " <<code <<endl;
	}
}

};

int main()
{
	float hh [100] ;
	int i = 0 ;
	int n = 0 ;
	string sentence = " " ;
	float count[256] = { 0 } ;

	 cout << "Enter your sentences ( End the sentence with . ): " << endl ;
	 getline(cin,sentence);

  for( int n = 0 ; n < sentence.length() ; n++ )
  {
    count[sentence[n]]++ ;
  }

  float mm = sentence.length() - 1 ;

  for ( n = 0 ; n < 256 ; n++ )
  {
    if ( isalpha ( ( char ) n ) )
    {
      cout << ( char ) n << " has " <<  count[n] << " occurrences " << " and has   " << count[n] / mm << endl ;
	
		hh[ n ] = ( count[ n ] / mm ) ;
		i++ ;
			 cout << "yay" << hh[n] << endl ;
	}
	int counter = 0 ;
	if( hh[n] != 0 )
	{
		counter++ ;
	}

	
  int x, y;
  float holder;

  // Bubble sort method. 
  for( x = 0; x < counter ; x++ )
    for( y = 0; y < x - 1 ; y++ )
      if(hh[y] > hh[y+1] )
	  {
        holder = hh[y+1] ;
        hh[y+1] = hh[y] ;
        hh[y] = holder ;
	    cout << hh[y] << "yay" ;
      } 	

	  queue<int>q;
	  
	  q.push(hh[y]);
	while (!q.empty())
    {
       q.front();
       q.pop();
    }

	
	while ( q.size() <1 ) {
		node *child0 = new node( q.front() );
		q.pop();
		node *child1 = new node( q.front() );
		q.pop();
		q.push( node( child0, child1 ) );
	}


  }


  
   return 0;
}

推荐答案

好吧,您可以为它提供一个整数,而不是节点地址...
Well, you could provide it with an int, rather than a node address...
queue<int>q;
...
q.push( node( child0, child1 ) );</int>



顺便说一句:使用更合理的名称,整理缩进,使代码更易于阅读,为什么现在仍必须调试的代码中仍然有跟踪语句?另外,请保持一致:我可以告诉您将其粘贴在一起,并希望它仅适用于各种花括号样式:K& R,无,缩进,部分缩进.梳理出来.选择一种样式,并坚持下去.否则,它将使您的代码更加难以阅读.



BTW: Use more sensible names, sort out your indentation so your code is easier to read, and why have you still got a tracing statements in code you presumably must have debugged by now? Also, be consistent: I can tell you are pasting this together and hoping it works just from the variety of curly bracket styles: K&R, none, indented, partially indented. Sort it out. Pick a style, and stick with it. Otherwise it makes your code even harder to read.


这篇关于我应该怎么做才能访问....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆