Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[I.suck.so.much.at.c++] Need newbie help
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Engineer
Expert Cheater
Reputation: 1

Joined: 25 Nov 2007
Posts: 170

PostPosted: Tue Jul 01, 2008 8:50 am    Post subject: [I.suck.so.much.at.c++] Need newbie help Reply with quote

I don't understand how to apply functions to classes... So I need your help (yhea I know I suck).

Here's a tiny,tiny,tiny script I made so you see how I write it down:

Code:
#include <iostream.h>
typedef unsigned short ush;

class Dog {
      public:
      ush age;
      ush weight;
      void Woof();
      }
     
      void Dog::Woof() {
           cout << "Oh hi! I'm a dog! Me luv you! Err... I mean.. Woof Woof!\n";
           }

int main() {
    Dog Nina;
   
    Nina.age = 5;
    Nina.Woof();
   
    system("pause");
    return 0;
}


I compile and I get 5 errors all pointing to Woof(), four at line 11, one at line 8.[/code]
Back to top
View user's profile Send private message
Zand
Master Cheater
Reputation: 0

Joined: 21 Jul 2006
Posts: 424

PostPosted: Tue Jul 01, 2008 8:57 am    Post subject: Reply with quote

std::cout?

class Dog {
public:
ush age;
ush weight;
void Woof();
};
Back to top
View user's profile Send private message
Engineer
Expert Cheater
Reputation: 1

Joined: 25 Nov 2007
Posts: 170

PostPosted: Tue Jul 01, 2008 9:07 am    Post subject: Reply with quote

Zand wrote:
std::cout?

class Dog {
public:
ush age;
ush weight;
void Woof();
};


std::cout makes no diference at all, you just type more...

Also, thanks
Back to top
View user's profile Send private message
Zand
Master Cheater
Reputation: 0

Joined: 21 Jul 2006
Posts: 424

PostPosted: Tue Jul 01, 2008 10:24 am    Post subject: Reply with quote

Compilers don't understand when you just type cout, unless you have a
using namespace std somewhere in front.

Still having errors?
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Tue Jul 01, 2008 10:55 am    Post subject: Reply with quote

Zand wrote:
Compilers don't understand when you just type cout, unless you have a
using namespace std somewhere in front.
They do if you
Code:
#include <iostream.h>
, but it isn't suggested to include the .h one (anymore..).

@Original poster: your mistake is that you've forgot a ; after the class presentation. Eg.
Code:
class Dog {
   void Woof();
};


Anyway.. This should work and be a bit more "proper" C++:
Code:
#include <iostream>
typedef unsigned short ush;

class Dog {
   public:
      ush age;
      ush weight;
      void Woof();
};
     
void Dog::Woof() {
   std::cout << "Oh hi! I'm a dog! Me luv you! Err... I mean.. Woof Woof!" << std::endl;
}

int main(int argc, char *argv[]) {
   Dog Nina;

   Nina.age = 5;
   Nina.Woof();
   
   std::cin.sync();
   std::cin.ignore();
   return EXIT_SUCCESS;
}


PS. I suggest you to use newer tutorials and NOT to use ::system("pause");
Back to top
View user's profile Send private message
Zand
Master Cheater
Reputation: 0

Joined: 21 Jul 2006
Posts: 424

PostPosted: Tue Jul 01, 2008 11:10 am    Post subject: Reply with quote

I've never done #include <iostream.h> before. I also never do (using namespace std), I just put all the std::'s.
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Tue Jul 01, 2008 12:09 pm    Post subject: Reply with quote

Code:
#include <iostream>

class Dog {
public:
      int age;
      int weight;

      Dog(int Age, int Weight) { age = Age; weight = Weight; }
      void Woof(void);
};

void Dog::Woof(void)
{
    std::cout << "Oh hi! I'm a dog! Me luv you! Err... I mean.. Woof Woof!\n";
}

int main(void)
{
    Dog *Nina = new Dog( 5, 68 );
    Nina->Woof();
   
    return 0;
}


I've always done classes like that =[
Back to top
View user's profile Send private message MSN Messenger
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Tue Jul 01, 2008 12:28 pm    Post subject: Reply with quote

noz3001 wrote:
I've always done classes like that =[
This was very very basic class/C++ stuff. I bet he doesn't know what's for example a pointer :)

Code:
class Dog {
private:
      int m_age, m_weight;

public:
      Dog(int Age, int Weight) { m_age = Age; m_weight = Weight; }
      void Woof(void);
};
Information hiding(, missing the setters and getters if they are needed) ;)
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Tue Jul 01, 2008 12:46 pm    Post subject: Reply with quote

Btw Jani, do you know a way to clear the console without using windows API or system?

Oops, Hijacked Thread.
Back to top
View user's profile Send private message MSN Messenger
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Wed Jul 02, 2008 9:55 am    Post subject: Reply with quote

noz3001 wrote:
Btw Jani, do you know a way to clear the console without using windows API or system?
Getting a bit off topic, but whatever. Nah, I haven't came across any really good way to clear the screen, which I could recommend. But I believe that if you can find some portable Curses library, it might have a way. I haven't personally ever tried coding with curses, and barely ever I've need a (portable) way to clear the screen. It's just nicer when everything is readable from the backlog or whatever it's called.

I think I could pass this question to Wiccaan, but I wouldn't count on him :p

PS. I do know that Curses is for *nix, but I bet someone has (tried to do/) done a portable one.

EDIT:
Wikipedia wrote:
Portability

Although the ncurses library was initially developed under Linux, OpenBSD, FreeBSD, and NetBSD it has been ported to many other ANSI/POSIX UNIX systems, mainly by Thomas Dickey. PDCurses, while not identical to ncurses, uses the same function calls and operates the same way as ncurses does except that PDCurses targets different devices, e.g., console windows for DOS, Win32, OS/2, as well as X11. Porting between the two is not difficult. For example, the roguelike game ADOM was written for Linux and ncurses, later ported to DOS and PDCurses.
You might want to check out PDCurses. Altho, if you're using it only to clear the screen, I guess it wouldn't be clever.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Fri Jul 04, 2008 3:20 pm    Post subject: Reply with quote

Clearing the console with API:

Code:
   CONSOLE_SCREEN_BUFFER_INFO pConsoleBufferInfo;
   COORD cCoords = {0};
   GetConsoleScreenBufferInfo( GetStdHandle(STD_OUTPUT_HANDLE), &pConsoleBufferInfo );
   FillConsoleOutputCharacter( GetStdHandle(STD_OUTPUT_HANDLE), 32, pConsoleBufferInfo.dwSize.X*pConsoleBufferInfo.dwSize.Y, cCoords, NULL );
   SetConsoleCursorPosition( GetStdHandle(STD_OUTPUT_HANDLE), cCoords );

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Fri Jul 04, 2008 3:47 pm    Post subject: Reply with quote

Wiccaan wrote:
Clearing the console with API:

Code:
   CONSOLE_SCREEN_BUFFER_INFO pConsoleBufferInfo;
   COORD cCoords = {0};
   GetConsoleScreenBufferInfo( GetStdHandle(STD_OUTPUT_HANDLE), &pConsoleBufferInfo );
   FillConsoleOutputCharacter( GetStdHandle(STD_OUTPUT_HANDLE), 32, pConsoleBufferInfo.dwSize.X*pConsoleBufferInfo.dwSize.Y, cCoords, NULL );
   SetConsoleCursorPosition( GetStdHandle(STD_OUTPUT_HANDLE), cCoords );


I used to use that way =D.
Back to top
View user's profile Send private message MSN Messenger
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Sat Jul 05, 2008 6:51 am    Post subject: Reply with quote

noz3001 wrote:
Btw Jani, do you know a way to clear the console without using windows API or system?
Wiccaan wrote:
Clearing the console with API:
:P
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sat Jul 05, 2008 8:45 am    Post subject: Reply with quote

Jani wrote:
noz3001 wrote:
Btw Jani, do you know a way to clear the console without using windows API or system?
Wiccaan wrote:
Clearing the console with API:
Razz


I know he wanted without, I was just tossing a with in here in case it was something he would want to fall back on. I don't think it's possible without using API, unless you get into some big ass chunk of inline ASM to clear the buffer and redraw the window manually. But you wouldn't really be doing much but more work. I think the above code is probably the best bet, the only other method I know of is using system, and yeah, I will never recommend that. >.>

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Sat Jul 05, 2008 10:30 am    Post subject: Reply with quote

Code:
void Clear(void)
{
    std::cout << "\033[2J";
}


So far that works. But I don't know whether it's good or not.
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites