473,396 Members | 1,689 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,396 software developers and data experts.

Non-aggregate type

MarkoKlacar
296 Expert 100+
Hi,

I have two problems.

I have a class a called Edit that contains the following:

Header
Expand|Select|Wrap|Line Numbers
  1. void setCharAt(int index,char ch);
  2. void rubout(int index) const;
  3. char text[];
  4.  
Problem 1:
Now, the rubout function takes an index and it's supposed to do something with this index in the char text[]. To be more specific, it's supposed to remove the char at the index position and pack the array.

The thing is when I try to get the length of the char tex[] I get this:

Expand|Select|Wrap|Line Numbers
  1. request for member `length' in `this->Edit::text', which is of on-aggregate type `char[0]'
Problem 2:
When I call the setCharAt(int index, char ch) it looks like this:
Expand|Select|Wrap|Line Numbers
  1. Edit::setCharAt(1,'v');
The error I get for this is:

Expand|Select|Wrap|Line Numbers
  1. passing `const Edit' as `this' argument of `void Edit::setCharAt(int, char)' discards qualifiers
What am I doing wrong?

Cheers.
May 15 '08 #1
5 3444
RRick
463 Expert 256MB
Its hard to tell what is going on without the actual code that is causing the problem. Please, we don't want to see all of your code, but a bit more is needed.

#1 looks like you are treating char [] like a string. I.e. ...myEdit.text.length(). That won't work. My sugestion is to make text a std::string.

#2 Somehow your edit object is a const and since since setCharAt is not a const method, the compiler will complain.

Finally, rubout is const, but it sounds like it will modify the text. That won't work either.
May 16 '08 #2
MarkoKlacar
296 Expert 100+
Hi,

Thanks for your response. As you mention, the methods rubout should not be const.

This is probably a noob issue. Could the fact that I'm calling a non-const method from a const method have anything to do with it?

I con provide you with more code, but I think you've gotten the problem.

Thanks in advance....

/M
May 16 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
text is a char array. It is not an object. There is no length member. Hence the error.

Maybe you meant you use a string object? If so, use the size() method for the length rather than the length() method. The length() method is deprecated.
May 16 '08 #4
MarkoKlacar
296 Expert 100+
Hey guys,

Thanks for the replies. But how do I tackle the other problem?

From a const method call a non-const method?
That's causing me problems...

Cheers
/M
May 17 '08 #5
weaknessforcats
9,208 Expert Mod 8TB
From a const method call a non-const method?
A non-const method (or any function for that matter) is one that can change variables outside the function. Like functions with pointer arguments.

You make a function const by making the arguments const:
Expand|Select|Wrap|Line Numbers
  1. void fx(const int* arg)
  2. {
  3.     *arg = 15;          //ERROR. the int is const.
  4. }
  5.  
That is, the const arguments reassures the compiler that the function cannot change anything outside the scope of the function:
Expand|Select|Wrap|Line Numbers
  1. void fx(const int* arg)
  2. {
  3.     cout << *arg << end;
  4. }
  5.  

This sort of const function can be called by a const member function.

Now for a const member funciton:
Expand|Select|Wrap|Line Numbers
  1. void MyClass::AMethod() const
  2. {
  3.       fx(this->APointerMember);     //OK. fx cannot change what APoionterMember points at
  4. }
  5.  

Remember, that member functions have an invisible first argument that is the this pointer. When you call a member function that has no arguments, there is actually one supplied by the compiler: The this pointer.

A member function can use the this pointer to chnage other class members unless the member function is const. A const member function is not allowed to change a class member.

Therefore, from within a const member function, you can call any function that has const pointer arguments, or other const member functions. And that's all.
May 18 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: lothar | last post by:
re: 4.2.1 Regular Expression Syntax http://docs.python.org/lib/re-syntax.html *?, +?, ?? Adding "?" after the qualifier makes it perform the match in non-greedy or minimal fashion; as few...
17
by: cheeser | last post by:
Hello all, Please see the question in the code below... Thanks! Dave #include <iostream>
5
by: klaus triendl | last post by:
hi, recently i discovered a memory leak in our code; after some investigation i could reduce it to the following problem: return objects of functions are handled as temporary objects, hence...
3
by: Mario | last post by:
Hello, I couldn't find a solution to the following problem (tried google and dejanews), maybe I'm using the wrong keywords? Is there a way to open a file (a linux fifo pipe actually) in...
1
by: Markus Ernst | last post by:
Hi I wrote a function that "normalizes" strings for use in URLs in a UTF-8 encoded content administration application. After having removed the accents from latin characters I try to remove all...
25
by: Yves Glodt | last post by:
Hello, if I do this: for row in sqlsth: ________pkcolumns.append(row.strip()) ________etc without a prior:
32
by: Adrian Herscu | last post by:
Hi all, In which circumstances it is appropriate to declare methods as non-virtual? Thanx, Adrian.
11
by: ypjofficial | last post by:
Hello All, So far I have been reading that in case of a polymorphic class ( having at least one virtual function in it), the virtual function call get resolved at run time and during that the...
399
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
12
by: puzzlecracker | last post by:
is it even possible or/and there is a better alternative to accept input in a nonblocking manner?
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: 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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.