vector of a class declared outside of dll

This is a discussion on vector of a class declared outside of dll within the C++ Programming forums, part of the General Programming Boards category; I'm getting these 2 errors: 14 K:\game\dll\level1\Level1.cpp `Enemy' is not a type 14 K:\game\dll\level1\Level1.cpp request for member of non-aggregate type ...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267

    vector of a class declared outside of dll

    I'm getting these 2 errors:
    14 K:\game\dll\level1\Level1.cpp `Enemy' is not a type
    14 K:\game\dll\level1\Level1.cpp request for member of non-aggregate type before '.' token

    and warnings from this code
    I'm new to dlls and vectors and have no idea what i'm doing

    what's wrong with my code and what's line 7 to 11 in Level.h do?

    Level1.cpp
    Code:
    #include "Level1.h"
    #include <windows.h>
    
    #include "..\..\source\enemy.h"
    
    extern std::vector<C_Level*> Level;
    extern std::vector<C_Enemy*> Enemy;
    
    __declspec(dllexport) void Level1()
    {
         Level.push_back(new C_Level);
         
         POINT P[] = {{0,0},{1,1},{2,2},{3,3},{5,5},{7,7},{12,12},{19,19},{20,20},{24,23}, {NULL, NULL}};
         Level[0].Enemy.push_back(new C_Enemy("enemy1", 10000, P)); //ERROR HERE
    }
    
    BOOL APIENTRY DllMain (HINSTANCE hInst     /* Library instance handle. */ ,
                           DWORD reason        /* Reason this function is being called. */ ,
                           LPVOID reserved     /* Not used. */ )
    {
        switch (reason)
        {
          case DLL_PROCESS_ATTACH:
            break;
    
          case DLL_PROCESS_DETACH:
            break;
    
          case DLL_THREAD_ATTACH:
            break;
    
          case DLL_THREAD_DETACH:
            break;
        }
    
        /* Returns TRUE on success, FALSE on failure */
        return TRUE;
    }
    Level1.h
    Code:
    #ifndef LEVEL1_H_INCLUDED
    #define LEVEL1_H_INCLUDED
    
    #include <vector>
    #include <windows.h>
    
    #if BUILDING_DLL
    # define DLLIMPORT __declspec (dllexport)
    #else /* Not BUILDING_DLL */
    # define DLLIMPORT __declspec (dllimport)
    #endif /* Not BUILDING_DLL */
    
    __declspec(dllexport) void Level1();
    
    #endif
    thanks in advance

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Code:
    Level[0].Enemy.push_back(new C_Enemy("enemy1", 10000, P)); //ERROR HERE
    Okay, I guess, each C_Level has a vector of C_Enemy *, and then you are adding one. I think what you might want is

    Code:
    Level[0]->Enemy.push_back(new C_Enemy("enemy1", 10000, P));
    So, I don't think that this is needed

    Code:
    extern std::vector<C_Enemy*> Enemy;
    Just a note

    Code:
    POINT P[] = {{0,0},{1,1},{2,2},{3,3},{5,5},{7,7},{12,12},{19,19},{20,20},{24,23}, {NULL, NULL}};
    First and last elements { 0, 0 } and { NULL, NULL } are the same.

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  3. #3
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267
    I made the changes but now i get the errors:
    [Linker error] undefined reference to `Level'
    [Linker error] undefined reference to `C_Enemy::C_Enemy(char*, unsigned int, tagPOINT*)'
    [Linker error] undefined reference to `Level'

    isnt "->" and "." the same thing?

    Code:
    #include "Level1.h"
    #include <windows.h>
    
    #include "..\..\source\enemy.h"
    
    extern std::vector<C_Level*> Level;
    //extern std::vector<C_Enemy*> Enemy;
    
    __declspec(dllexport) void Level1()
    {
         Level.push_back(new C_Level);
         
         POINT P[] = {{0,0},{1,1},{2,2},{3,3},{5,5},{7,7},{12,12},{19,19},{20,20},{24,23}, {-1, -1}};
         Level[0]->Enemy.push_back(new C_Enemy("enemy1", 10000, P));
    }
    
    BOOL APIENTRY DllMain (HINSTANCE hInst     /* Library instance handle. */ ,
                           DWORD reason        /* Reason this function is being called. */ ,
                           LPVOID reserved     /* Not used. */ )
    {
        switch (reason)
        {
          case DLL_PROCESS_ATTACH:
            break;
    
          case DLL_PROCESS_DETACH:
            break;
    
          case DLL_THREAD_ATTACH:
            break;
    
          case DLL_THREAD_DETACH:
            break;
        }
    
        /* Returns TRUE on success, FALSE on failure */
        return TRUE;
    }

  4. #4
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    >> isnt "->" and "." the same thing?

    http://msdn2.microsoft.com/en-us/library/b930c881.aspx

    Code:
    [Linker error] undefined reference to `Level'
    [Linker error] undefined reference to `C_Enemy::C_Enemy(char*, unsigned int, tagPOINT*)'
    [Linker error] undefined reference to `Level'
    Well, you told the compiler that 'Level' was defined somewhere else with this statement:

    Code:
    extern std::vector<C_Level*> Level;
    And apparently it isn't. You also told it that C_Enemy has a constructor that takes 3 arguments (c-string, uint, array of points), but apparently it does not.

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 02-14-2008, 01:59 PM
  2. DLL question
    By cboard_member in forum Game Programming
    Replies: 1
    Last Post: 04-24-2006, 02:19 AM
  3. Calling a class member through a pointer to a class in a DLL
    By cboard_member in forum C++ Programming
    Replies: 1
    Last Post: 04-19-2006, 10:55 AM
  4. dll communicating between each other
    By cloudy in forum C++ Programming
    Replies: 5
    Last Post: 06-17-2005, 02:20 AM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 01:30 PM

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