Hi,

why is it giving me the warning: deprecated conversion from string constant to ‘char*’
How may I fix this?

Any help is welcome

#include <iostream>
using namespace std;

class Melarki
{
	public:
		Melarki(): first(""){};
		Melarki(char * mimi): first(mimi){};
		~Melarki(){delete first;};
	
	
		char * first;
};


int main()
{
	Melarki wholeMelarki("Stuff");
	return 0;
}

Recommended Answers

All 2 Replies

A string literal is a constant value in modern C and C++, so the pointer to it has const char* type (not char* ). The Melarki constructor wants char* argument. Why? It's a very dangerous class. For example, your program is evidently wrong: Melarki destructor called for wholeMelarki will try to deallocate "Stuff" literal in static memory!

Alas, for backward compatibility such (wrong) literal usage treated as deprecated (but not invalid).

You can fix this error if you redesign this class - deallocation bomb from the scratch...

commented: Thank you +1

ArkM,
thank you. Both problems understood and fixed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.