sending a 'const char*' parameter to a function that recives 'const char* &'

why is this not OK?

void func(const char* &pointer){...}


//in main
const char* mainPointer = "a word";
func(mainPointer);

my intention is to send a pointer to a function, that changes it(the pointer) but doesn't change the chars it is pointing to.

Answers


The following code (MS Visual C++ 2010) shows that it is perfectly possible and works. The output is: "World!"

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


void func(const char*& ptr) 
{
    ptr += 6;
}


int _tmain(int argc, _TCHAR* argv[])
{
    const char* Ptr = "Hello World!";
    func(Ptr);
    cout << Ptr << endl;
    return 0;
}

Note that in contrast to Null Voids code, we do modify the pointer within func here.


Need Your Help

jQuery TimePicker - using dd/mm/yyyy

jquery timepicker

Has anyone used Trent Richardsons TimePicker?

Override application root

asp.net asp.net-mvc-3 iis-7.5

I have an application in iis available as http://localhost/app/ which means that all relative links created by UrlHelper are resolved as http://localhost/app/???.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.