When compiling the code, I am getting the error string.cpp: In member function ‘size_t String::len() const':
string.cpp:105:33: error: passing ‘const String' as ‘this' argument of ‘int String::strlen(const char*)' discards qualifiers
Could anyone help me to fix this problem?
for a temporary workaround I am using the
Calling a member function "const" is to guarantee to the compiler "this function modifies absolutely nothing in this class". You are calling a non-const member function(strlen) from a const member function, hence the error.
Which is to say, if you made your strlen() member const too, the error should stop.
'retstring' should be returning 'const char *'.
I'm not sure why you bothered making strlen() when you could have just #include <stdio.h>.
Last edited by Corona688; 09-26-2013 at 02:19 PM..
These 2 Users Gave Thanks to Corona688 For This Post:
Hello All,
I am a learner in C++. I was testing my inheritance knowledge with following piece of code.
#include <iostream>
using namespace std;
class base
{
public :
void display()
{
cout << "In base display()" << endl;
}
void display(int k)
{... (2 Replies)
Hello,
I want to check whether string has only numeric characters. The following code doesn't work for me
#!/usr/local/bin/bash
if ]]; then
echo "true"
else
echo "False"
fi
# ./yyy '346'
False
# ./yyy 'aaa'
False
I'm searching for solution using character classes, not regex.... (5 Replies)
I have the two class definition as follows.
class A { public: int a; };
class B : virtual public A{ };
The size of class A is shown as 4, and size of class B is shown as 16. Why is this effect ?. (2 Replies)
Hi all!
I am trying to register a device in an existing device class, but I am
having trouble getting the pointer to an existing class.
I can create a class in a module, get the pointer to it and then use
it to register the device with:
*cl = class_create(THIS_MODULE, className);... (0 Replies)
I've notepad in which logs are present. I need to design a web page by which if some one paste their ticket number and click on "search" the logs for that ticket number should be displayed at the bottom.
I need some advice on how to do this and which is the right platform to do this.
Regards... (1 Reply)
I have a requirement where I collect inputs from entry widget in gui(via variables a,b,c) and then output a string like this: -a a -b b -c c.
Hence if I have given a=1 b=2 c=3, The output string is --> -a 1 -b 2 -c 3
or if I have given a=1 b=2 (c left blank) then the output is --> -a 1... (1 Reply)
Hi, i have a question about C++. Is it possible to declare a class with a member ot the same class? For example, a linked list or i want to convert this C code to C++ class (Elemento)
typedef struct elemento
{
char name;
char value;
List<struct elemento> ltElementos;
... (7 Replies)
Can anybody tell me what is the best website or books to read for getting good knowledge in doing C++ class design. Please leave cplusplus.com or bjorne stroustrup. Other than these is there any website or book. Please do tell me (0 Replies)