Thread: Constructor implementation...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    11

    Constructor implementation...

    Code:
    Board::Board(Shape size)
    : myAircraftCarrier(Vector location(Object.RandInt(1, size.Length()), Object.RandInt(1, size.Width()), Shape size(4,1)),
      myBattleship(Vector location(Object.RandInt(1, size.Length()), Object.RandInt(1, size.Width()), Shape size(3,2)),
      myCruiser(Vector location(Object.RandInt(1, size.Length()), Object.RandInt(1, size.Width()), Shape size(3,1)),
      mySubmarine(Vector location(Object.RandInt(1, size.Length()), Object.RandInt(1, size.Width()), Shape size(2,1)),
      myDestroyer(Vector location(Object.RandInt(1, size.Length()), Object.RandInt(1, size.Width()), Shape size(1,1)),
      mySize(size.Length(), size.Width())
    {
    
    }
    What's wrong with this implementation? I'm creating the new vector object inside of the implementation, but I don't see the problem.

    'c:\my documents\visual studio projects\battleship\board.cpp(15) : error C2275: 'Vector' : illegal use of this type as an expression'

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    You shouldn't be naming the instances. Try this -

    myAircraftCarrier(Vector (Object.RandInt(1, size.Length()), Object.RandInt(1, size.Width()), Shape size(4,1)),

    //etc

Popular pages Recent additions subscribe to a feed
Website Security Test