LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 11-22-2009, 04:38 PM   #1
holystinken
LQ Newbie
 
Registered: Nov 2009
Posts: 4

Rep: Reputation: 0
invalid conversion from `const char*' to `char' error


I am trying to get my code to work for chars it works for ints but when I try to use it for chars it gives me the error invalid conversion from `const char*' to `char' here is my code

#include <iostream>
#include <fstream>
#include <map>
#include <string>
#include <iterator>
using namespace std;



class mystack
{
public:
int size;
char* stacker;
int topg;
char a;
char data;
mystack(){
topg = -1;
size = 1;
stacker =new char[size];
}
~mystack(){
if(stacker) delete[] stacker;
}
char push(char a){

size++;
topg++;
stacker[topg] = a;
return 0;
}
char pop()
{
char data = stacker[topg];
topg--;
cout << data << endl;
return data;
}
int top(){ return topg;}

};

int main()
{
mystack a;
a.push("a");
a.push();
a.pop();
cout << a.top() << endl;
system("pause");
}

I just need to understand why exactly i am getting this error and what I can do to change it
 
Old 11-22-2009, 04:43 PM   #2
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,538

Rep: Reputation: 58
Next time highlight the line that the compiler is complaining about (yes, it does give you a line). Otherwise we have to manually dig through it, like I just did.

Your function is declared as
Code:
char push(char a)
but your calling it as
Code:
a.push("a");
You need to pass a char, not a string (i.e. char*). "a" is a string but 'a' is a char.
 
Old 11-22-2009, 04:45 PM   #3
holystinken
LQ Newbie
 
Registered: Nov 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Sorry about that I will definatly rememebr for next time thanks for the quick reply though
 
Old 11-22-2009, 05:14 PM   #4
holystinken
LQ Newbie
 
Registered: Nov 2009
Posts: 4

Original Poster
Rep: Reputation: 0
ccould you elaborate a little more because I have tried changing my function char push(char a) to just char push() and other things as well with no success I am still kind of lost.
 
Old 11-22-2009, 05:16 PM   #5
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,538

Rep: Reputation: 58
Your function definition is fine, the problem is with how your calling it, as I said above.

Your doing
Code:
a.push("a");
but you need to do
Code:
a.push('a');
.

Also remove the line after your first push, as it will give an error. That is, remove this
Code:
a.push();
 
Old 11-22-2009, 05:26 PM   #6
holystinken
LQ Newbie
 
Registered: Nov 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Oh wow see I thought I had tried that but, I guess not because it did work thank you so much for your help I really apperciate it
 
Old 11-22-2009, 11:20 PM   #7
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: washington U.S.
Distribution: Damn Small Linux, KateOs, M$ Ickdows Vista, My own OS
Posts: 2,094

Rep: Reputation: 104Reputation: 104
Please click the blue hand button on the right bottom corner of any post that has helped you.
 
Old 11-23-2009, 06:01 PM   #8
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,538

Rep: Reputation: 58
Ya, good idea
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
error: invalid conversion from const char* to char* Dahakon Programming 1 08-31-2009 09:33 AM
Problems with "error: invalid conversion from `const char*' to `char*' " dave.f.one Linux - Newbie 10 11-19-2008 10:01 AM
about C++ invalid conversion from 'const char*' to 'char' teoporta Programming 3 07-17-2007 09:24 AM
invalid conversion from `const char*' to `char*' deepinlife Programming 22 08-05-2006 10:49 AM
If I get invalid conversion from `const char*' to `char' what should I be lookin for? RHLinuxGUY Programming 5 03-12-2006 10:35 PM


All times are GMT -5. The time now is 09:36 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration