New Header and CPP file

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
User avatar
Fenlig
Posts: 16
Joined: April 12th, 2013, 10:51 am

New Header and CPP file

Post by Fenlig » May 10th, 2013, 10:01 am

Hey Guys,

I'm trying to make a CPP file and header file but it keeps erroring out. Not sure what I'm doing wrong!

Shapes.h

Code: Select all

#pragma once

class Shapes
{
public:
	void DrawSquare( int size,int offsetX,int offsetY,int r,int g,int b);
private:
}

Shapes.cpp

Code: Select all

#include "Shapes.h"
#include "D3DGraphics.h"

void Shapes::DrawSquare( int size,int offsetX,int offsetY,int r,int g,int b)
{
	for(int y = 0; y <= size; y++)
	{
		for(int x = 0; x <= size; x++)
		{
			D3DGraphics::PutPixel(x,y,r,g,b);
		}
	}
}
Error:

Code: Select all

1>------ Build started: Project: Chili DirectX Framework, Configuration: Release Win32 ------
1>  Game.cpp
1>c:\users\simon.kay\documents\c++\tetris\assets\Game.h(45): error C2236: unexpected 'class' 'Game'. Did you forget a ';'?
1>c:\users\simon.kay\documents\c++\tetris\assets\Game.h(45): error C2143: syntax error : missing ';' before '{'
1>c:\users\simon.kay\documents\c++\tetris\assets\Game.h(45): error C2447: '{' : missing function header (old-style formal list?)
1>..\Assets\Game.cpp(26): error C2653: 'Game' : is not a class or namespace name
1>..\Assets\Game.cpp(27): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>..\Assets\Game.cpp(31): error C2550: 'Game' : constructor initializer lists are only allowed on constructor definitions
1>..\Assets\Game.cpp(32): warning C4508: 'Game' : function should return a value; 'void' return type assumed
1>..\Assets\Game.cpp(34): error C2653: 'Game' : is not a class or namespace name
1>..\Assets\Game.cpp(36): error C2065: 'gfx' : undeclared identifier
1>..\Assets\Game.cpp(36): error C2228: left of '.BeginFrame' must have class/struct/union
1>          type is ''unknown-type''
1>..\Assets\Game.cpp(37): error C3861: 'ComposeFrame': identifier not found
1>..\Assets\Game.cpp(38): error C2065: 'gfx' : undeclared identifier
1>..\Assets\Game.cpp(38): error C2228: left of '.EndFrame' must have class/struct/union
1>          type is ''unknown-type''
1>..\Assets\Game.cpp(41): error C2653: 'Game' : is not a class or namespace name
1>  Shapes.cpp
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(29): error C2628: 'Shapes' followed by 'unsigned' is illegal (did you forget a ';'?)
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(29): error C2628: 'Shapes' followed by 'int' is illegal (did you forget a ';'?)
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(29): error C2347: '__w64' : can not be used with type '__w64 Shapes'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(29): error C2371: 'size_t' : redefinition; different basic types
1>          predefined C++ types (compiler internal)(19) : see declaration of 'size_t'
1>..\Assets\Shapes.cpp(10): error C2352: 'D3DGraphics::PutPixel' : illegal call of non-static member function
1>          c:\users\simon.kay\documents\c++\tetris\assets\D3DGraphics.h(34) : see declaration of 'D3DGraphics::PutPixel'
1>  Windows.cpp
1>c:\users\simon.kay\documents\c++\tetris\assets\Game.h(45): error C2236: unexpected 'class' 'Game'. Did you forget a ';'?
1>c:\users\simon.kay\documents\c++\tetris\assets\Game.h(45): error C2143: syntax error : missing ';' before '{'
1>c:\users\simon.kay\documents\c++\tetris\assets\Game.h(45): error C2447: '{' : missing function header (old-style formal list?)
1>..\Assets\Windows.cpp(163): error C2065: 'Game' : undeclared identifier
1>..\Assets\Windows.cpp(163): error C2146: syntax error : missing ';' before identifier 'theGame'
1>..\Assets\Windows.cpp(163): error C3861: 'theGame': identifier not found
1>..\Assets\Windows.cpp(176): error C2065: 'theGame' : undeclared identifier
1>..\Assets\Windows.cpp(176): error C2228: left of '.Go' must have class/struct/union
1>          type is ''unknown-type''
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Thanks Simon,

krrice
Posts: 6
Joined: February 7th, 2012, 2:51 am

Re: New Header and CPP file

Post by krrice » May 10th, 2013, 12:45 pm

#pragma once

class Shapes
{
public:
void DrawSquare( int size,int offsetX,int offsetY,int r,int g,int b);
private:
} <-- You forgot to put a ; here

User avatar
Fenlig
Posts: 16
Joined: April 12th, 2013, 10:51 am

Re: New Header and CPP file

Post by Fenlig » May 10th, 2013, 1:09 pm

That worked, but now it is saying that 'Shapes' : no appropriate constructor available. :(

Any Ideas?

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: New Header and CPP file

Post by LuX » May 12th, 2013, 5:34 pm

You need a constuructor for a class if you use it in some way. Like for just crating a class "Class exmple" you need an empty constuctor "Class ( ) { }" in the class. Same if you need to initialize something, just create an appropriate constructor.

In other words, just add the line "Shapes ( ) { };" in the public section of the class Shapes. Compare with the Game class constructor.
ʕ •ᴥ•ʔ

Post Reply