473,394 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

What is wrong about the DrawEngine?

93 64KB
Hey, it has been a while and I'm back with another problem with my c++ code...

This time it's about a header function (the constructor DrawEngine) in my DrawEngine.cpp file(the DrawEngine.h file that is included in this, is down below)...

Error: line 7, expected unqualified-id before "int"
Error: line 7, expected ")" before "int"

DrawEngine.cpp:

Expand|Select|Wrap|Line Numbers
  1. #ifndef DrawEngine_cpp
  2. #define DrawEngine_cpp
  3.  
  4. #include <windows.h>
  5. #include "DrawEngine.h"
  6.  
  7. DrawEngine(int xSize, int ySize)
  8. {
  9.     int screenWidth = xSize;
  10.     int screenHeight = ySize;
  11.  
  12.     //set cursor vivbility to false at start up
  13. }
  14. DrawEngine::~DrawEngine()
  15. {
  16.     //set cursor visibility to true at end
  17. }
  18.  
  19. int DrawEngine::createPlayer(int index, int skin, int idNumber)
  20. {
  21.     //set player model, index, skin and the idNumber of the user
  22. }
  23.  
  24. int DrawEngine::drawPlayer(int index, int idNumber, int posx, int posy)
  25. {
  26.     //go to the correct location
  27.     gotoxy(posx, posy);
  28.     //draw the player
  29.     //switch this out for a command to draw the player
  30. }
  31.  
  32. void DrawEngine::gotoxy(int x, int y)
  33. {
  34.     HANDLE output_handle;
  35.     COORD pos;
  36.  
  37.     pos.X = x;
  38.     pos.Y = y;
  39.  
  40.     output_handle = GetStdHandle(STD_OUTPUT_HANDLE);
  41.  
  42.     SetConsoleCursorPosition(output_handle, pos);
  43. }
  44. #endif DrawEngine_cpp
  45.  
DrawEngine.h:

Expand|Select|Wrap|Line Numbers
  1. #ifndef DrawEngine_H
  2. #define DrawEngine_H
  3.  
  4. #include <windows.h>
  5.  
  6. class DrawEngine
  7. {
  8. public:
  9.     int xSize;
  10.     int ySize;
  11.     DrawEngine(int xSize = 800, int ySize = 600);
  12.     ~DrawEngine();
  13.  
  14.     int createPlayer(int index, int skin, int idNumber);
  15.     void deletePlayer(int index);
  16.  
  17.     void erasePlayer(int posx, int posy);
  18.     int drawPlayer(int index, int idNumber, int posx, int posy);
  19.  
  20.     void playerModel(int idNumber, int playerData, int playerId);
  21.  
  22.     void cursorVisibility(bool Visibility);
  23. protected:
  24.     int screenWidth, screenHeigth;
  25.  
  26. private:
  27.     void gotoxy(int x, int y);
  28. };
  29.  
  30. #endif
  31.  
Dec 31 '13 #1

✓ answered by weaknessforcats

You should never need to use the .cpp file more than once in a project. If you are doing that, then you have a function in disguise.

Go to all the places you use that .cpp code and replace that with a function call. Then have one instance of the .cpp in your project written as a function that is called from everywhere else.

I see other problems in the code but they relate to OO coding and design issues. Since the code works for you, there is no need for me to say anything. Working code trumps my opinions.

13 1291
Xillez
93 64KB
The "DrawEngine::DrawEngine()" thing in DrawEngine.cpp? then I get the error: multiple definition of `DrawEngine::DrawEngine(int, int)'
Dec 31 '13 #2
zmbd
5,501 Expert Mod 4TB
I had to rethink that, what is the namespace you are using?
Also something about how you have line7 doesn't read right... shouldn't be?
Expand|Select|Wrap|Line Numbers
  1. drawEngine::drawEngine(int index, int xSize, int ySize)
??
Dec 31 '13 #3
Xillez
93 64KB
The Namespace/the name of the class is "DrawEngine"

It's the same as

Expand|Select|Wrap|Line Numbers
  1. DrawEngine::DrawEngine(int index, int xSize, int ySize)
"...

It says that in the .cpp file I redefine it...
Dec 31 '13 #4
zmbd
5,501 Expert Mod 4TB
I don's see where you have the name space set, ie:
Expand|Select|Wrap|Line Numbers
  1. using namespace std;
anywhere within your cpp

However, if you don't want my help.
Dec 31 '13 #5
Xillez
93 64KB
I want your help... you know how you can do for example

Expand|Select|Wrap|Line Numbers
  1. std::cout
where you have the "Namespace"::"Command/function"

I'm trying to do that since it gives me an error when I try to make it a namespace... but it doesn't work, maybe it's something wrong with my DrawEngine.h?
Dec 31 '13 #6
zmbd
5,501 Expert Mod 4TB
you might also look at the start of the CPP:
where's the
Expand|Select|Wrap|Line Numbers
  1. #endif
Also...
Expand|Select|Wrap|Line Numbers
  1. #include "drawEngine.h"
  2. #include <windows.h>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. DrawEngine::DrawEngine(int xSize, int ySize)
  8. {
  9.     screenWidth = xSize;
  10.     screenHeight = ySize;
  11.  
  12.     //set cursor visibility to false
  13.     cursorVisibility(false);
This is from the evilmonkey tutorial - yes?
That's where I picked this up from anyway.
Dec 31 '13 #7
Xillez
93 64KB
hehehe, yes, but it's modified...

forget the
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
forgot to delete that...

(where I copied from):http://www.3dbuzz.com/training/view/...ev/draw-engine
Dec 31 '13 #8
weaknessforcats
9,208 Expert Mod 8TB
Is there still an issue here?

I saw this:

Expand|Select|Wrap|Line Numbers
  1. #ifndef DrawEngine_cpp
  2. #define DrawEngine_cpp
  3. etc...
Inclusion guards are not put in .cpp files because these files are never included.

The inclusion guard only protects against being included more than once in the same .cpp. This applies only to header files.

What is your issue with the namespace?

Namespaces are open-ended so unlike a struct there is no one place you can go to see what's in the namespace. If you code:

Expand|Select|Wrap|Line Numbers
  1. namespace Xillez
  2. {
  3.      class DrawEngine
  4.      {
  5.        etc...
  6. }
you have Xillez::DrawEngine but you have no idea what else might be in this namespace.
Dec 31 '13 #9
Xillez
93 64KB
let's forget the #findef DrawEngine_Cpp thing because it's not giving me any errors, but the compiler says that I redefine the DrawEngine::DrawEngine(int index, int xSize, int ySize) in the DrawEngine.cpp.

How can I get rid of this error with the current code?
Dec 31 '13 #10
weaknessforcats
9,208 Expert Mod 8TB
There is no error in the current code other than DrawEngine function must be DrawEngine::DrawEngine.

A couple of other functions need to return values but the functions don't appear coded yet so I made them return 0.

With those changes the code compiles and links for me.

The only way you are going to get a redefine on the DrawEngine::DrawEngine is if there a two bodies for the function. This usually happens when a .cpp file is in the project twice. Those #ifndef in the .cpp file lead me to believe you are using this file more than once in your project.
Jan 1 '14 #11
Xillez
93 64KB
yes, I am... when ever a game rescieves and update, it's going to print on the screen... but not so much that it crashes the game XD

So there isn't a problem in code execpt that?
Jan 1 '14 #12
weaknessforcats
9,208 Expert Mod 8TB
You should never need to use the .cpp file more than once in a project. If you are doing that, then you have a function in disguise.

Go to all the places you use that .cpp code and replace that with a function call. Then have one instance of the .cpp in your project written as a function that is called from everywhere else.

I see other problems in the code but they relate to OO coding and design issues. Since the code works for you, there is no need for me to say anything. Working code trumps my opinions.
Jan 1 '14 #13
Xillez
93 64KB
ok, thanks man for the help XD
Jan 2 '14 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Lee Redeem | last post by:
Hi there I've created abd uploaded this basic PHP script: <html> <head> <title>PHP Test</title> </head> <body> <H1 align="center">
4
by: Fang | last post by:
Hi, I'm new to PHP. I followed an example on the book and wanted to pass a variable from one html page to a php page, but it always tells me the passed variable is undefined. I've checked the...
3
by: Ali | last post by:
The following program is supposed to display a dropdown menu, however, it only shows the File and Help things. from Tkinter import * root = Tk() #create menu m = Menu(root)...
1
by: Thorsan | last post by:
im doing the following: int _tmain(int argc, _TCHAR* argv) { typedef double matrix4x4; matrix4x4 *mat = (matrix4x4*)malloc(sizeof(matrix4x4));
5
by: Koen | last post by:
Hi all, I am experimenting with DAO. I wrote this sub to update one specific field of one specific row in one specific table. Nothing wrong with the SQL statement, but when I execute this I get...
8
by: Polaris | last post by:
Hi Experts: The program creates Panels and inicilize them. When I run the code below, the program crashes (at the line commented below). Any help is appriciated. Thanks in Advance! Polaris ...
2
by: MikeY | last post by:
Hi Everyone, I'm having problems with my syntax on the updating part for the Northwind.MDB. All other code seems fine. It has to do with the Order Details on the thisAdapter.Update( ). Or I...
14
by: howa | last post by:
void reverse_string(char *str) { if (str == NULL) return; char tmp; size_t len = strlen(str); size_t mid = (int) len / 2; for (size_t i = 0; i < mid; i++) {
2
by: doudou88 | last post by:
Hello, I try to debug a c# program using mono-debugger. But i need first to create .exe.mdb file, using the folowing command: gmcs -debug program.cs When doing this I get the following error:...
3
by: muddasirmunir | last post by:
I am trying to give the following Icon in my form in vb6. http://www.mediafire.com/?ymzgkgyi50j But , when I put this in my form I got error "Invalid Picutre" What wrong in it? How to add...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.