Help with constructors.

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
cameron
Posts: 794
Joined: June 26th, 2012, 5:38 pm
Location: USA

Help with constructors.

Post by cameron » March 8th, 2013, 2:18 am

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 ==========
Computer too slow? Consider running a VM on your toaster.

cameron
Posts: 794
Joined: June 26th, 2012, 5:38 pm
Location: USA

Re: Help with constructors.

Post by cameron » March 11th, 2013, 11:02 pm

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.

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Help with constructors.

Post by albinopapa » March 12th, 2013, 6:53 am

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.
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

cameron
Posts: 794
Joined: June 26th, 2012, 5:38 pm
Location: USA

Re: Help with constructors.

Post by cameron » March 12th, 2013, 10:03 pm

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.

User avatar
Nosferatu
Posts: 36
Joined: July 25th, 2012, 7:08 am
Location: Slovakia

Re: Help with constructors.

Post by Nosferatu » March 13th, 2013, 3:23 pm

Well, I don't know if this is your case, but som errors like:

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,
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.

cameron
Posts: 794
Joined: June 26th, 2012, 5:38 pm
Location: USA

Re: Help with constructors.

Post by cameron » March 14th, 2013, 12:32 am

Heres my whole project.
Attachments
Income wars - Copy - Copy - Copy-WorkInProgress - Copy (2).rar
(647.08 KiB) Downloaded 158 times
Computer too slow? Consider running a VM on your toaster.

Musi
Posts: 106
Joined: November 25th, 2012, 1:06 am

Re: Help with constructors.

Post by Musi » March 14th, 2013, 6:48 am

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 :) .
Musi

There are 10 types of people that understand binary.
Those that do, and those that don't.

User avatar
Nosferatu
Posts: 36
Joined: July 25th, 2012, 7:08 am
Location: Slovakia

Re: Help with constructors.

Post by Nosferatu » March 14th, 2013, 3:06 pm

Musi wrote:In Surface.h remove #include "SurfaceSequence.h"....
.
Well that is what I was trying to say ;)

cameron
Posts: 794
Joined: June 26th, 2012, 5:38 pm
Location: USA

Re: Help with constructors.

Post by cameron » March 14th, 2013, 10:00 pm

Thanks for the help.
Computer too slow? Consider running a VM on your toaster.

Post Reply