Array of classes within class definition

This is a discussion on Array of classes within class definition within the C++ Programming forums, part of the General Programming Boards category; Does anyone know how to get this code to work? It compiles fine in Visual Studio, but not in Borland. ...

  1. #1
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    359

    Array of classes within class definition

    Does anyone know how to get this code to work? It compiles fine in Visual Studio, but not in Borland. I need this to work in Borland.
    All I want to do is locally decare an array of classes within a class, and initalise them to their relevant values. However, in Borland I keep getting these errors:

    [C++ Error] TJunction.h(21): E2034 Cannot convert 'A' to 'A[3]'
    [C++ Error] TJunction.h(28): E2176 Too many types in declaration

    Code:
    class A
    {
      public:
        A(int i) : m_i(i) {}
    
      protected:
        int m_i;
    };
    
    class B
    {
      public:
        B() : m_A(A(1), A(2), A(3)) {}
    
      protected:
        A m_A[3];
    }
    Any help would be greatful
    Be a leader and not a follower.

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Creating a database
    By Shamino in forum Game Programming
    Replies: 19
    Last Post: 06-10-2007, 01:09 PM
  3. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 04:01 PM
  4. dynamic array of base class pointers
    By Corrington_j in forum C++ Programming
    Replies: 1
    Last Post: 11-16-2003, 04:58 AM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21