LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-19-2006, 10:32 AM   #1
Dstruct0
Member
 
Registered: Jun 2005
Distribution: Debian Etch, Lenny, Squeeze
Posts: 37

Rep: Reputation: 0
Why double standard?


I'm trying learn gnu c++. And already found a problem. Why the following first code snippet complains but the other doesn't?

Code:
   int **aa = new int*[3];

   aa[0] = new int[2];

   *(*(aa + 0) + 0) = 1;

   cout << (*aa[0])[0] << endl; //complains about: error: invalid types `int[int]' for                             
                                //array subscript

--------------------------------------------------------------------------------------------------------------


   string *first_names[100];

   string first = "LLLL";

   first_names[0] = new string(first);

   cout << (*first_names[0])[0] << endl; //doesn't complain
I can access one array with this notation but not the other? Can anyone kindly explain?

Thanks.
 
Old 04-19-2006, 10:47 AM   #2
addy86
Member
 
Registered: Nov 2004
Location: Germany
Distribution: Debian Testing
Posts: 332

Rep: Reputation: 31
aa[0] is of type int*
*aa[0] is of type int (and equivalent to aa[0][0])
firstnames[0] is of type string*
*firstnames[0] is of type string (and equivalent to firstnames[0][0])

std::string overloads operator[], int doesn't; that's why (*aa[0])[0] will give you an error.
You probably meant aa[0][0] (and firstnames[0][0]).
 
Old 04-19-2006, 10:56 AM   #3
Dstruct0
Member
 
Registered: Jun 2005
Distribution: Debian Etch, Lenny, Squeeze
Posts: 37

Original Poster
Rep: Reputation: 0
Thank you for clearing this up for me. I'm enjoyin' every moment of c++. Again thanks.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Double the desktop, not double the fun! bizshop SUSE / openSUSE 3 08-26-2005 12:22 PM
double in C greg108 Programming 3 09-28-2004 03:36 PM
Why am I seeing double in X? linuxenthusiast Linux - Newbie 1 01-11-2004 02:23 PM
Double Up SpEcIeS Linux - General 1 08-26-2003 01:21 PM
standard vs Expert install? Standard flubs up! Frost Linux - Software 1 03-27-2002 07:55 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration