473,382 Members | 1,717 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Pointer to pointer to const conversions

Quick question. Why, in the following code sample, can I not convert a
char ** to a const char **?

void test(const char **p)
{
cout << str(*p) << '\n';
}

int main()
{
char *str = new char[10];
char **pstr = &str;

test(pstr);

return 0;
}

My error output is:

1>------ Build started: Project: test, Configuration: Debug Win32
1>Compiling...
1>test.cpp
1>test.cpp(3) : error C2065: 'cout' : undeclared identifier
1>test.cpp(3) : error C3861: 'str': identifier not found
1>test.cpp(11) : error C2664: 'test' : cannot convert parameter 1
from 'char **' to 'const char **'
1> Conversion loses qualifiers
1>Build log was saved at "file://xxxxxx\Debug\BuildLog.htm"
1>test - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped

Any help would be appreciated. I'm sure someone must have brought this
issue up before, but it's not easy to search for, let's put it that way.

Jun 21 '06 #1
3 2253
Corrected code:

#include <iostream>
#include <string>

using namespace std;

void test(const char **p)
{
cout << string(*p) << '\n';
}

int main()
{
char *str = new char[10];
char **pstr = &str;

test(pstr);

return 0;
}

Sorry about that.

Jun 21 '06 #2
James Aguilar wrote:
Quick question. Why, in the following code sample, can I not convert a
char ** to a const char **?
...


See the FAQ

http://www.parashift.com/c++-faq-lit...html#faq-18.17

--
Best regards,
Andrey Tarasevich
Jun 21 '06 #3
James Aguilar posted:
Quick question. Why, in the following code sample, can I not convert a
char ** to a const char **?

Here's something that was posted not so long ago:

http://groups.google.ie/group/comp.s...eb07061?hl=en&
Jun 22 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: cppaddict | last post by:
I can't figure out why this code won't work, or how to fix it: list<MyClass> l; int main() { for (int i=0;i<5;i++) { MyClass* myClass = new MyClass; myClass -> someInitMethod();...
10
by: homecurr | last post by:
Here is my code Class A; Class B; Class C : public A, public B { .... } Class D {
5
by: Ingo Nolden | last post by:
Hi there, I am writing a smart pointer that is similar to the boost intrusive ptr. I am trying to make it behave like a c++ pointer including the implicit and explicit casting behaviour. Below...
22
by: Alex Fraser | last post by:
From searching Google Groups, I understand that void pointer arithmetic is a constraint violation, which is understandable. However, generic functions like qsort() and bsearch() must in essence do...
204
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 =...
10
by: vb | last post by:
Hi all, I am a newbie in C and i want to know what all pointer conversions are "legal" according to ANSI C standard. For Example, int* to char*, some_struct* to char* and so on .. According to...
26
by: Bill Reid | last post by:
Bear with me, as I am not a "professional" programmer, but I was working on part of program that reads parts of four text files into a buffer which I re-allocate the size as I read each file. I...
1
by: Ilya N. Golubev | last post by:
There is already one function processing pointer values this way. And there may easily appear more, including wrappers for this function. For purposes of further discussion, consider simplified...
11
by: quakewang | last post by:
hi, I have define in a head file like this: #define GLUT_BITMAP_9_BY_15 ((void*)2) #define GLUT_BITMAP_8_BY_13 ((void*)3) #define GLUT_BITMAP_TIMES_ROMAN_10 ...
5
by: jason.cipriani | last post by:
There have been some recent threads about casting pointers to and from void* that have me rethinking some of my usual practices. I have a couple of questions. 1. What is the purpose of C++'s...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.