Nested Union Structure and scope resolution operator

From: Camford (Cam_at_mac.ca.ku)
Date: 04/15/04


Date: Thu, 15 Apr 2004 19:34:46 +0100

I have just started on C++. Today I tried to compile the following source
and I got some error messages.

#include <iostream>
#include <string>

using namespace std; //introduces namespace std

union myunion2
{
 struct Point3d
 {
  float x;
  float y;
  float z;
 }
 pt;

 struct Rectangle
 {
  int l;
  int t;
  int r;
  int b;
 }
 rect;
};

void main( )
{
 myunion2 mu;

 mu.Point3d::x = 1.0f; //this line gives the error. Illegal use of
non-static member
 //rest of the code
 cout << "This is a test" ;
 ;
}

I got the code from a book called "Using C++" by Rob McGregor, published
1998. I tried to compile the source using both C++ Builder and Metrowerks
CodeWorrier with no luck. Any help on the proper usage of nested structure
and scope resolution operator will be appreciated.

-- 
Camford
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.657 / Virus Database: 422 - Release Date: 13/04/2004


Relevant Pages

  • newbie help - running program
    ... i am trying to compile and run the following code. ... using namespace std; ... Lines(float, float, float); ... test to see if two lines are parallel, perpendicular, ...
    (alt.comp.lang.learn.c-cpp)
  • newbie help - running program
    ... i am trying to compile and run the following code. ... using namespace std; ... Lines(float, float, float); ... test to see if two lines are parallel, perpendicular, ...
    (comp.lang.cpp)
  • Re: RAD vs. performance
    ... You may be inclined to say 'int', ... available in hardware (int and float). ... Only at the cost of vastly longer compile times and incremental compilation ...
    (comp.lang.misc)
  • Re: STL on Solaris system
    ... I would like compile a little program in c++ ... using namespace std; ... test.cpp: In function 'int main': ... This is free software; see the source for copying conditions. ...
    (comp.unix.solaris)
  • Re: collect2: ld returned 8 exit status
    ... I'm trying to compile a short piece of code in C++: ... using namespace std; ... int main ... $ g++ test.cpp -o testcpp ...
    (comp.unix.aix)