LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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-30-2004, 04:19 AM   #1
ashwinipahuja
Member
 
Registered: Mar 2004
Posts: 79

Rep: Reputation: 15
Unhappy Hi dakensta- one more problem- "Not an aggregate type"


Hi dakensta,

I am experiencing one more problem releated to aggregate type errors.

The code is as follows

#include<iostream>
using namespace std;
class xyz
{
public:
typedef enum {a=0,b,c,d} control;
};
int main()
{
if( xyz::control::a == 0)
{
}
return 0;
}


Thanx in advance
Ashwini
 
Old 04-30-2004, 04:53 AM   #2
ashwinipahuja
Member
 
Registered: Mar 2004
Posts: 79

Original Poster
Rep: Reputation: 15
Try Again

Last edited by ashwinipahuja; 04-30-2004 at 06:32 AM.
 
Old 04-30-2004, 05:00 AM   #3
dakensta
Member
 
Registered: Jun 2003
Location: SEUK
Distribution: Debian & OS X
Posts: 194

Rep: Reputation: 35
if( xyz::control::a == 0)

You don't want 'control' in there.
a,b,c and d are constants in the scope of xyz.
control is a type within the scope of xyz.

So you have xyz::a, xyz::b, xyz::c, xyz::d and xyz::control used:
xyz::control my_value = xyz::a;

Also, in this statement:
typedef enum {a=0,b,c,d} control;

in c++ (as opposed to c) you can just write

enum control {a=0,b,c,d};

Think of it like a struct or class ...
struct control { /* Whatever*/ };

gives you the ability to say:
control c;
in your code.

If you look at c code you will often see something more like
struct control c;
because you do not have the implicit type.

class xyz
{
enum {a=0,b,c,d} control;
}
is giving you a member control of class xyz. of type enum.
preceding this with typedef (as you have and want but do not need to) makes control a type in the scope of xyz.

Yes, it is confusing - it is for me. I would suggest using a reference book just to confirm these points, regarding the precise usage.

It gets pretty in depth.
I might edit this a bit after reading back.
Summary:
Code:
class xyz 
{
enum {a=0,b,c,d};                    // 1. Gives you xyz::a , xyz::b as CONSTANTS.
enum {a=0,b,c,d} control;      // 2. Gives you xyz::control as a MEMBER of xyz
enum control {a=0,b,c,d};      // 3. Gives you xyz::control as a TYPE 
           //      and xyz::a etc. as CONSTANTS
typedef enum {a=0,b,c,d} control; // Same as 3.

};
I think

Last edited by dakensta; 04-30-2004 at 05:27 AM.
 
Old 04-30-2004, 06:42 AM   #4
ashwinipahuja
Member
 
Registered: Mar 2004
Posts: 79

Original Poster
Rep: Reputation: 15
Thanx dakensta,

The following code works fine..
#include<iostream>
using namespace std;
class xyz
{
public:
typedef enum {a=0,b,c,d} control;
};
int main()
{
xyz::control d;
d=xyz::a;
cout<<d;
return 0;
}
 
  


Reply



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
Simple Ooo BASIC Macro problem: "connot coerce argument type..." tredegar Linux - Software 0 08-14-2005 10:00 AM
web surfing problem... i have to type in "http://" fatrandy13 Linux - Software 8 05-23-2005 02:48 AM
extern "C" and static data type problem with g++ vtluu Programming 2 04-28-2004 05:10 AM
"Not an aggregate type"- Error in g++ ashwinipahuja Programming 2 04-26-2004 06:14 AM
<input type="button" disabled="true" > does not work in ns4.7 or 4.9 cybercop12us Programming 2 11-29-2002 08:31 AM

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

All times are GMT -5. The time now is 09:48 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