SunQuest
           C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old May 7th, 2008, 01:04 AM
alexb119 alexb119 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 2 alexb119 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 43 sec
Reputation Power: 0
Array of structs

Hi

I'm trying to use an array of structs of class AnyClass arrays:

struct XElSymbol
{
AnyClass PlinePts[4];
AnyClass LinePts[2];
};
XElSymbol Symbols[2];//array of 2 XElSymbol structs

Symbols[1].PlinePts[0].set(0,0,0);//try to access the array

and I keep getting compiler errors for the last code line:
error C2143: syntax error : missing ';' before '.'
error C4430: missing type specifier - int assumed.

Apparently the compiler sees the access to the array as a declaration of an int array by the same name (the symbol Symbols appears twice in the class explorer) and can't be persuaded otherwise.

BTW, the error is not related to the class used, it occurs even if we use just int's

It's probably some stupid error but can somebody help me out?


Thanks

alex

Reply With Quote
  #2  
Old May 7th, 2008, 06:21 AM
L7Sqr L7Sqr is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2004
Location: Constant Limbo
Posts: 587 L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 12 h 50 m 31 sec
Reputation Power: 100
Send a message via AIM to L7Sqr
Quote:
Symbols[1].PlinePts[0].set(0,0,0);
is probably happening outside the scope of any function (including main).
Fore example:
Code:
class AnyClass {
        public:
                void set(int a,int b, int c) { }
};

struct X {
        AnyClass P[4];
};

X data[2];
data[1].P[2].set(1,2,3);

int main () {
        return 0;
}

Produces:
Quote:
Originally Posted by g++
error: expected constructor, destructor, or type conversion before '.' token

But
Code:
        public:
                void set(int a,int b, int c) { }
};

struct X {
        AnyClass P[4];
};

X data[2];

int main () {
        data[1].P[2].set(1,2,3);
        return 0;
}
Compiles without error.
Your results may vary as you are not using g++, but my guess is that that should fix your problem.
__________________
-- I'll provide you with reference points; if they dont work, refer to something else.

If you process text, this might make your life a little easier.

Reply With Quote
  #3  
Old May 7th, 2008, 12:32 PM
alexb119 alexb119 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 2 alexb119 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 43 sec
Reputation Power: 0
Thank you L7Sqr

It's just as you wrote:

"...is probably happening outside the scope of..."

Moved it to its proper place and it compiles OK.

Thanks again.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Array of structs


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway