Help with constructors.
Help with constructors.
I get a bunch of garbage errors for this.
Building.h:
#pragma once
#include "Surface.h"
#include "D3DGraphics.h"
#include <string>
#include <stdio.h>
class Building
{
private:
KeyedSurface keyedsurface;
int BuildingX;
int BuildingY;
float BuildingDamage;
public:
Building( std::wstring& filename, D3DCOLOR key );
void DrawBase( D3DGraphics& gfx ) const;
void Attack( float& UnitHealth, int& Unitx, int& Unity );
void Draw( D3DGraphics& gfx );
void Do( D3DGraphics& gfx, float& UnitHealth, int& Unitx, int& Unity );
public:
float BuildingHP;
};
Building.cpp:
#include "Building.h"
Building::Building( std::wstring& filename, D3DCOLOR key )
: keyedsurface( filename, key )
{}
void Building::Draw( D3DGraphics& gfx )
{
if( BuildingHP > 0 )
{
Draw( gfx );
}
}
void Building::Attack( float& UnitHealth, int& Unitx, int& Unity )
{
if( Unitx > SCREENWIDTH - 400 )
{
Unity = UnitHealth - BuildingDamage;
}
}
void Building::Do( D3DGraphics& gfx, float& UnitHealth, int& Unitx, int& Unity )
{
DrawBase( gfx );
Attack( UnitHealth, Unitx, Unity );
}
Errors:
1>------ Build started: Project: Chili DirectX Framework, Configuration: Debug Win32 ------
1> Building.cpp
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(57): error C2143: syntax error : missing ';' before '*'
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(57): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(57): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(19): error C2065: 'surfaces' : undeclared identifier
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(19): error C2061: syntax error : identifier 'KeyedSurface'
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(20): warning C4018: '<' : signed/unsigned mismatch
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(24): error C2065: 'surfaces' : undeclared identifier
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(24): error C2061: syntax error : identifier 'KeyedSurface'
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(30): warning C4018: '<' : signed/unsigned mismatch
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(32): error C2065: 'surfaces' : undeclared identifier
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(35): error C2065: 'surfaces' : undeclared identifier
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(35): error C2541: 'delete' : cannot delete objects that are not pointers
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(39): error C2065: 'surfaces' : undeclared identifier
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(39): error C2227: left of '->Draw' must point to class/struct/union/generic type
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(43): error C2065: 'surfaces' : undeclared identifier
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(43): error C2227: left of '->BackwardsDraw' must point to class/struct/union/generic type
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\building.cpp(4): error C2512: 'KeyedSurface' : no appropriate default constructor available
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\building.cpp(18): warning C4244: '=' : conversion from 'float' to 'int', possible loss of data
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Building.h:
#pragma once
#include "Surface.h"
#include "D3DGraphics.h"
#include <string>
#include <stdio.h>
class Building
{
private:
KeyedSurface keyedsurface;
int BuildingX;
int BuildingY;
float BuildingDamage;
public:
Building( std::wstring& filename, D3DCOLOR key );
void DrawBase( D3DGraphics& gfx ) const;
void Attack( float& UnitHealth, int& Unitx, int& Unity );
void Draw( D3DGraphics& gfx );
void Do( D3DGraphics& gfx, float& UnitHealth, int& Unitx, int& Unity );
public:
float BuildingHP;
};
Building.cpp:
#include "Building.h"
Building::Building( std::wstring& filename, D3DCOLOR key )
: keyedsurface( filename, key )
{}
void Building::Draw( D3DGraphics& gfx )
{
if( BuildingHP > 0 )
{
Draw( gfx );
}
}
void Building::Attack( float& UnitHealth, int& Unitx, int& Unity )
{
if( Unitx > SCREENWIDTH - 400 )
{
Unity = UnitHealth - BuildingDamage;
}
}
void Building::Do( D3DGraphics& gfx, float& UnitHealth, int& Unitx, int& Unity )
{
DrawBase( gfx );
Attack( UnitHealth, Unitx, Unity );
}
Errors:
1>------ Build started: Project: Chili DirectX Framework, Configuration: Debug Win32 ------
1> Building.cpp
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(57): error C2143: syntax error : missing ';' before '*'
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(57): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(57): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(19): error C2065: 'surfaces' : undeclared identifier
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(19): error C2061: syntax error : identifier 'KeyedSurface'
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(20): warning C4018: '<' : signed/unsigned mismatch
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(24): error C2065: 'surfaces' : undeclared identifier
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(24): error C2061: syntax error : identifier 'KeyedSurface'
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(30): warning C4018: '<' : signed/unsigned mismatch
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(32): error C2065: 'surfaces' : undeclared identifier
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(35): error C2065: 'surfaces' : undeclared identifier
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(35): error C2541: 'delete' : cannot delete objects that are not pointers
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(39): error C2065: 'surfaces' : undeclared identifier
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(39): error C2227: left of '->Draw' must point to class/struct/union/generic type
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(43): error C2065: 'surfaces' : undeclared identifier
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(43): error C2227: left of '->BackwardsDraw' must point to class/struct/union/generic type
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\building.cpp(4): error C2512: 'KeyedSurface' : no appropriate default constructor available
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\building.cpp(18): warning C4244: '=' : conversion from 'float' to 'int', possible loss of data
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Computer too slow? Consider running a VM on your toaster.
Re: Help with constructors.
I know there are a few oblivious errors. But the weird ones i think have to do with the constructor.
Computer too slow? Consider running a VM on your toaster.
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Help with constructors.
If you are referring to the Building class constructor, the syntax in the .cpp file looks correct. The compiler seems to be only complaining about the missing types such as KeyedSurface. Assuming the class or struct KeyedSurface has been created elsewhere fixing the first error will sometimes fix several other errors as the compiler may be confused where the class or struct begins or ends.
Fix the errors you know are wrong then if you still have errors and can't figure them out post the new output log.
Fix the errors you know are wrong then if you still have errors and can't figure them out post the new output log.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
Re: Help with constructors.
There are no errors in the surface class because if I completely wipe the building.cpp file it gives no errors so I have no clue.
Computer too slow? Consider running a VM on your toaster.
Re: Help with constructors.
Well, I don't know if this is your case, but som errors like:
I used to get when I improperly included files. For example, let's say you have class Player and class Bullet.
Player has a member of type Bullet and Bullet has a member of type Player( I know it's nonsense, but just for explanation's sake ). The thing is that in bullet.h you need to include Player.h and likewise in Player.h you need Bullet.h. This means that the compiler would read player.h and then bullet.h and again player.h and so on...
As I've said I'm not sure if this is your case, but if so the only way around this is to include files properly, which I haven't been able to learn yet
Edit: If you post the whole project, I will have a look at it and tell you if this is the problem.
Code: Select all
workinprogress\assets\surfacesequence.h(57): error C2143: syntax error : missing ';' before '*'
1>c:\users\camer_000\desktop\income wars - copy - copy - copy-workinprogress\assets\surfacesequence.h(57): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int,
Player has a member of type Bullet and Bullet has a member of type Player( I know it's nonsense, but just for explanation's sake ). The thing is that in bullet.h you need to include Player.h and likewise in Player.h you need Bullet.h. This means that the compiler would read player.h and then bullet.h and again player.h and so on...
As I've said I'm not sure if this is your case, but if so the only way around this is to include files properly, which I haven't been able to learn yet
Edit: If you post the whole project, I will have a look at it and tell you if this is the problem.
Re: Help with constructors.
Heres my whole project.
- Attachments
-
- Income wars - Copy - Copy - Copy-WorkInProgress - Copy (2).rar
- (647.08 KiB) Downloaded 164 times
Computer too slow? Consider running a VM on your toaster.
Re: Help with constructors.
In Surface.h remove #include "SurfaceSequence.h".
You can't have two header files that include each other. If both files depend on each other a way to get around this is first make a forward declaration of the SerfaceSequence class in Surface.h, then #include SurfaceSequence.h in the Surface.cpp file instead. This is one reason why you shouldn't put everything in header files .
You can't have two header files that include each other. If both files depend on each other a way to get around this is first make a forward declaration of the SerfaceSequence class in Surface.h, then #include SurfaceSequence.h in the Surface.cpp file instead. This is one reason why you shouldn't put everything in header files .
Musi
There are 10 types of people that understand binary.
Those that do, and those that don't.
There are 10 types of people that understand binary.
Those that do, and those that don't.
Re: Help with constructors.
Well that is what I was trying to sayMusi wrote:In Surface.h remove #include "SurfaceSequence.h"....
.
Re: Help with constructors.
Thanks for the help.
Computer too slow? Consider running a VM on your toaster.