5 Replies - 21314 Views - Last Post: 02 March 2008 - 02:17 PM Rate Topic: -----

#1 Delta_Echo  Icon User is offline

  • D.I.C Addict

Reputation: 5
  • View blog
  • Posts: 722
  • Joined: 24-October 07

cannot convert ‘bool’ to ‘bool*’ in assignment

Posted 02 March 2008 - 01:46 AM

Sorry, my post is the attachment. I can't post it because i get a 403 Forbidden when i do. ( i think its the code tags )
Thanks for reading :)

</Dream.In.Code>

Attached File(s)

  • Attached File  post.txt (2.57K)
    Number of downloads: 266

This post has been edited by Delta_Echo: 02 March 2008 - 01:47 AM

Is This A Good Question/Topic? 0
  • +

Replies To: cannot convert ‘bool’ to ‘bool*’ in assignment

#2 Nayana  Icon User is offline

  • DIC Hawk - 나야나 नयन:
  • member icon

Reputation: 32
  • View blog
  • Posts: 824
  • Joined: 14-November 07

Re: cannot convert ‘bool’ to ‘bool*’ in assignment

Posted 02 March 2008 - 01:58 AM

Quote

This is very odd. I am trying to write a function that will clear the screen ( in a shell environment ) on any OS, so i don't have to make multiple versions of code.
I thought i would be as simple as:

Ask for OS
Set a bool value to true ( linux ) false ( windows )
use if/else to input a command to the shell ( reset/cls respectively )
and that would be that.

Seems so simple....
note: The code is actually for a game but I wanted the function to be reusable, guess i should do
what pro programmers do and recycle :)

Code:

core.cpp:
#include <iostream>
#include <ctime>
#include <string>
#include <stdlib.h>
#include <fstream> 

#include "c_clsf.h"

using namespace std;

int main () 
{
	 // Function Prototype
	 void c_cls(void);
	 // Data
	 char name[101]; 
	 int os_c;
	 bool os;		// True= Linux False= Windows
	 // Arrays
	 // Pointers
	 bool *p_os;
	 p_os = &os;  
   
	
  cout << "What Operating System (OS) are you using?\n";
  cout << "1. Linux/ Mac Os X \n";
  cout << "2. Windows \n"; 
  cout << "> "; cin >> os_c;  
  cin.ignore(); 

	   switch ( os_c )
	   { 
		  case 1: 
		 {  
			os = true;
			break;
		 }  
		  case 2: 
		 {  
			os = false;
			break; 
		 }	
			default: 
		   { 
			cout << "Error!: Illegal Choice!: Setting Default OS mode (Linux).\n";
			cin.get(); 
			os = true;
		   }
	  } 
			
		c_cls();
 
		  cout << "Whats your name my lord?\n";
		  cout << "> "; cin >> name; 
		  cin.getline ( name, 101 ); 
}			 



c_clfs.h :
 
/* USE: 
  ----
Function created for easy "clear-screen" operation 
on either Linux, Mac Os, or Windows. Because, if
the wrong command is input into the shell in-which 
the game is operating in, it will interupt gameplay!  
*/

#include <stdlib.h> 

void c_cls(void)
{
  bool *p_os;
  bool os;
  p_os = &os;
   
	if ( p_os = true )
  { 
	system ("reset"); 
  }
	else ( p_os = false )
  {  
	system ("cls");
  } 
   

}
// END



It is the console build command, that causes DIC to send a 403 - Forbidden.

Here's the error message he got after compiling:

c_clsf.h: In function 'void c_cls()':
c_clsf.h:17: error: cannot convert 'bool' to 'bool*' in assignment
c_clsf.h:22: error: expected ';' before '{' token

This post has been edited by Nayana: 02 March 2008 - 01:59 AM

Was This Post Helpful? 0
  • +
  • -

#3 Delta_Echo  Icon User is offline

  • D.I.C Addict

Reputation: 5
  • View blog
  • Posts: 722
  • Joined: 24-October 07

Re: cannot convert ‘bool’ to ‘bool*’ in assignment

Posted 02 March 2008 - 02:11 AM

What do you mean it causes dic to send an error? You mean the compiler output i included? How?

Thanks for your help :)

This post has been edited by Delta_Echo: 02 March 2008 - 02:13 AM

Was This Post Helpful? 0
  • +
  • -

#4 Nayana  Icon User is offline

  • DIC Hawk - 나야나 नयन:
  • member icon

Reputation: 32
  • View blog
  • Posts: 824
  • Joined: 14-November 07

Re: cannot convert ‘bool’ to ‘bool*’ in assignment

Posted 02 March 2008 - 02:17 AM

And your error is in this line in c_clfs.h
if ( p_os = true )



Which is attempting to assign true to the pointer p_os. I guess the C++ compiler doesn't like it.

---
it was the line just before your error message that caused DIC to throw a hissy fit. I don't know why.
Was This Post Helpful? 0
  • +
  • -

#5 Delta_Echo  Icon User is offline

  • D.I.C Addict

Reputation: 5
  • View blog
  • Posts: 722
  • Joined: 24-October 07

Re: cannot convert ‘bool’ to ‘bool*’ in assignment

Posted 02 March 2008 - 02:27 AM

Know of any other way i could achieve the same objective?
Was This Post Helpful? 0
  • +
  • -

#6 Trogdor  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 15
  • View blog
  • Posts: 627
  • Joined: 06-October 06

Re: cannot convert ‘bool’ to ‘bool*’ in assignment

Posted 02 March 2008 - 02:17 PM

if(os){

or
if(*p_os){

or
if(os == true){

= is for asignment, == is for comparing.

after you fix that, the else part will fail. take a look again in your C book at if-else statements why.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1