Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Can vectors really hold classes?

Can vectors really hold classes?

Scheduled Pinned Locked Moved C / C++ / MFC
questiongraphicsgame-devhelp
4 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lord Kixdemp
    wrote on last edited by
    #1

    Hello everyone! OK, I have: vector<Vehicle> vehicles; Class Vehicle doesn't have a constructor. However, when I add a constructor, I get this error on the line in which vehicles is declared (see above): 1>c:\incoming\war game\Game.h(11) : error C2065: 'Vehicle' : undeclared identifier The declaration of the constructor is as follows: Vehicle(int x, int y, int id); What is wrong with this code? Thanks!

    Windows Calculator told me I will die at 28. :(

    G 1 Reply Last reply
    0
    • L Lord Kixdemp

      Hello everyone! OK, I have: vector<Vehicle> vehicles; Class Vehicle doesn't have a constructor. However, when I add a constructor, I get this error on the line in which vehicles is declared (see above): 1>c:\incoming\war game\Game.h(11) : error C2065: 'Vehicle' : undeclared identifier The declaration of the constructor is as follows: Vehicle(int x, int y, int id); What is wrong with this code? Thanks!

      Windows Calculator told me I will die at 28. :(

      G Offline
      G Offline
      Gerald Schwab
      wrote on last edited by
      #2

      If you don't add a constructor, the compiler automatically adds an emtpty one for you. Add an empty constructor to your class, and it should work.

      L 1 Reply Last reply
      0
      • G Gerald Schwab

        If you don't add a constructor, the compiler automatically adds an emtpty one for you. Add an empty constructor to your class, and it should work.

        L Offline
        L Offline
        Lord Kixdemp
        wrote on last edited by
        #3

        That's the problem - if I add an (empty) constructor, it gives me the error... It's error-free when I don't add one. ;P

        Windows Calculator told me I will die at 28. :(

        M 1 Reply Last reply
        0
        • L Lord Kixdemp

          That's the problem - if I add an (empty) constructor, it gives me the error... It's error-free when I don't add one. ;P

          Windows Calculator told me I will die at 28. :(

          M Offline
          M Offline
          markkuk
          wrote on last edited by
          #4

          You must add a default constructor that doesn't need any parameters: Vehicle::Vehicle()

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups