Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualJonBMN

Posted 17 August 2012 - 11:20 AM

I'm creating a class for a later program called EthicalCompetition. I'm stuck on an error code and don't truely understand the meaning of it, if anyone could help me out I would be very appreciated.

#include "stdafx.h"
#include <iostream>
using namespace std;
class EthicalCompetition
{
private:
class Connection;
public:
void HardWork();
};
class EthicalCompetition::Connection{
protected:
friend class EthicalCompetition;
void Connect();
Connection() {}
~Connection() {}
};
void EthicalCompetition::HardWork()
{
Connection c;
c.Connect();
cout << "Connected" << endl;
}
void EthicalCompetition::Connection::Connection()
{
cout << "Connecting..." << endl;
}
int main(int argc, char *argv[])
{
//EthicalCompetition::Connection myconnect;
EthicalCompetition comp;
comp.HardWork();
system("pause");
return 0;
}

error code

1>------ Build started: Project: Tracing, Configuration: Debug Win32 ------
1> Tracing.cpp
1>c:\users\jonbecher\documents\visual studio 2012\projects racing racing racing.cpp(26): error C2533: 'EthicalCompetition::Connection::{ctor}' : constructors not allowed a return type
1>c:\users\jonbecher\documents\visual studio 2012\projects racing racing racing.cpp(26): error C2084: function 'EthicalCompetition::Connection::Connection(void)' already has a body
1> c:\users\jonbecher\documents\visual studio 2012\projects racing racing racing.cpp(16) : see previous definition of '{ctor}'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

#1JonBMN

Posted 17 August 2012 - 11:19 AM

I'm creating a class for a later program called EthicalCompetition. I'm stuck on an error code and don't truely understand the meaning of it, if anyone could help me out I would be very appreciated.

[source lang="cpp"]#include "stdafx.h"#include <iostream>using namespace std;class EthicalCompetition{private: class Connection;public: void HardWork();};class EthicalCompetition::Connection{protected: friend class EthicalCompetition; void Connect(); Connection() {} ~Connection() {}};void EthicalCompetition::HardWork(){ Connection c; c.Connect(); cout << "Connected" << endl;}void EthicalCompetition::Connection::Connection() { cout << "Connecting..." << endl;}int main(int argc, char *argv[]){ //EthicalCompetition::Connection myconnect; EthicalCompetition comp; comp.HardWork(); system("pause"); return 0;}[/source]

error code

1>------ Build started: Project: Tracing, Configuration: Debug Win32 ------
1> Tracing.cpp
1>c:\users\jonbecher\documents\visual studio 2012\projects\tracing\tracing\tracing.cpp(26): error C2533: 'EthicalCompetition::Connection::{ctor}' : constructors not allowed a return type
1>c:\users\jonbecher\documents\visual studio 2012\projects\tracing\tracing\tracing.cpp(26): error C2084: function 'EthicalCompetition::Connection::Connection(void)' already has a body
1> c:\users\jonbecher\documents\visual studio 2012\projects\tracing\tracing\tracing.cpp(16) : see previous definition of '{ctor}'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

PARTNERS