Thread: Compiler thinks I'm defining when I'm trying to call

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    24

    Compiler thinks I'm defining when I'm trying to call

    I'm trying to create a DX sprite...
    Code:
    LPD3DXSPRITE d3dspt;
    LPDIRECT3DTEXTURE9 sprite;
    	
    D3DXCreateSprite(d3ddev, &d3dspt);
    D3DXCreateTextureFromFile(d3ddev, L"panel1.png", &sprite);
    ...and I'm getting this...
    Code:
    render.cpp(25) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    render.cpp(25) : error C2365: 'D3DXCreateSprite' : redefinition; previous definition was 'function'
    d3dx9core.h(234) : see declaration of 'D3DXCreateSprite'
    render.cpp(25) : error C2078: too many initializers
    render.cpp(25) : error C2440: 'initializing' : cannot convert from 'LPD3DXSPRITE *' to 'int'
    1>        There is no context in which this conversion is possible
    render.cpp(26) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    render.cpp(26) : error C2365: 'D3DXCreateTextureFromFileW' : redefinition; previous definition was 'function'
    d3dx9tex.h(1076) : see declaration of 'D3DXCreateTextureFromFileW'
    render.cpp(26) : error C2078: too many initializers
    render.cpp(26) : error C2440: 'initializing' : cannot convert from 'LPDIRECT3DTEXTURE9 *' to 'int'
    1>        There is no context in which this conversion is possible
    Last edited by alanb; 08-28-2009 at 09:44 PM.

  2. #2
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    are you doing this inside a function?
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    24
    No, I'm doing it directly in the source file after some preprocessor stuff.

  4. #4
    Registered User
    Join Date
    Aug 2009
    Posts
    24
    Got it!

    I moved it all into a function but I had 'undeclared' errors, then I realised that the two declarations needed a wider scope and I put them at the top of the file and the two next lines inside a function.

    Why was it necessary for those lines to be inside a function?

  5. #5
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    All code (statements which do something at runtime) must be located inside a function.

    Having statements at global scope is not possible, because C and C++ programs can be composed of multiple modules. Suppose two modules A.cpp and B.cpp both have code at the global scope. When these two modules are compiled and linked together, which code should execute first -- the statements from A.cpp or the ones from B.cpp?

    Because this question has no clear answer, code statements are not allowed at the global scope.

    In C++, where it is possible to declare global objects which have constructors, this problem actually still exists. It's not defined what order global objects from different modules will be constructed, and this leads to problems in practice.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  6. #6
    Registered User
    Join Date
    Aug 2009
    Posts
    24
    Aha, I see.

    It will take a while for me to un-learn inline programming. OOP has much potential but right now it just seems like a pain. Thanks for the assist.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. lcc win32 compiler download problems
    By GanglyLamb in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 08-01-2004, 07:39 PM
  2. OpenScript2.0 Compiler
    By jverkoey in forum C++ Programming
    Replies: 3
    Last Post: 10-30-2003, 01:52 PM
  3. Compiler Design... Anyone That Can Help!
    By ComputerNerd888 in forum C++ Programming
    Replies: 3
    Last Post: 09-27-2003, 09:48 AM
  4. Help needed with external call, WinExec() and timer.
    By algorithm in forum Windows Programming
    Replies: 9
    Last Post: 11-07-2001, 09:35 AM
  5. Pls help me to do this project in C I need source code
    By sureshmenon74 in forum C Programming
    Replies: 4
    Last Post: 10-04-2001, 06:57 AM