Jump to content
  • Advertisement
Sign in to follow this  
ARC inc

Problems

This topic is 3566 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, so it's me again = ) <hope your not tired of me yet> anyways I am working on my GameServer an I've decided to put the GameServer in a console app. It's been awhile since I've done a Console and a few things have been well lost(it happens) I was running a test to make sure I remember how to make a void function and print out the information it contains, to my main.cpp and well I keep on getting errors, I am not sure what I am doing wrong. main.cpp
#include <iostream>
#include <windwos.h>
#include "corefunctions.h"

using namespace std;

int main()
{

void GameConnect();

             cout << GameConnect() << endl;

return 0;
}

corefunctions.h
#ifndef COREFUNCTIONS_H
#define COREFUNCTIONS_H

void GameConnect()

#endif
corefunctions.cpp
#include <iostream>
#include "corefunctions.h"

using namespace std;

void GameConnect();

              cout << "GameConnection test!"<< endl;

return 0;
}
I know I did something wrong it does not feel right, it's just been awhile since I've done things like this.

Share this post


Link to post
Share on other sites
Advertisement
Second, function prototypes end with a semicolon, not the functions themselves.


// main.cpp
...
int main()
{

void GameConnect(); // Remove the function prototype, as it's defined in your header

cout << GameConnect() << endl;

return 0;
}
...

// corefunctions.cpp

...
void GameConnect(); // Get rid of the semicolon here, and add a {

cout << "GameConnection test!"<< endl;

return 0;
}
...

#ifndef COREFUNCTIONS_H
#define COREFUNCTIONS_H

void GameConnect() // Add a semicolon here

#endif







Share this post


Link to post
Share on other sites
Oh lol, forgot to mention what errors I was getting lol


I am getting errors with using namespace it says something like I need to use something before using



Share this post


Link to post
Share on other sites
Ok, yah now I got the problem fixed but now....

when I run the program it executes but it prints

1

thats it...I don't know what the heck happened.

Share this post


Link to post
Share on other sites
Dude, copy and paste. Learn it, live it, love it. It's both less effort that typing things out and more useful.

Share this post


Link to post
Share on other sites
Quote:
Original post by ARC inc
Ok, yah now I got the problem fixed but now....

when I run the program it executes but it prints

1

thats it...I don't know what the heck happened.


ok, look at GameConnect.


void GameConnect()
{
cout << "GameConnection test!"<< endl;

return 0;
}




Notice anything wrong? You might want to look at how you define GameConnect.

Share this post


Link to post
Share on other sites
So, this works (function returns nothing, is simply called):

#include <iostream>

void addition(int, int);

int main()
{
addition(5,7);

return 0;
}

void addition(int x, int y)
{
std::cout << "This is some text\n";
std::cout << (x + y) << "\n";

return;
}



And this works (function returns an int, used in-line with cout):

#include <iostream>

int addition(int, int);

int main()
{
std::cout << addition(5,7) << "\n";

return 0;
}

int addition(int x, int y)
{
std::cout << "This is some text\n";

return x + y;
}



But this doesn't, I think it has something to do with using the stream operator on a void return type:

#include <iostream>

void addition(int, int);

int main()
{
std::cout << addition(5,7) << "\n";

return 0;
}

void addition(int x, int y)
{
std::cout << "This is some text\n";
std::cout << (x + y) << "\n";

return;
}

Share this post


Link to post
Share on other sites
From MSDN:
"When used as a function return type, the void keyword specifies that the function does not return a value"

I'm trying to help the OP by showing various working versions of an example of what he's trying to do. Calling a void function like a value-returning function obviously doesn't compile in this case.

edit: in my example case (codeblock 3), you receive "error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'void' "

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!