Embedded Help!

Started by
8 comments, last by rip-off 11 years, 8 months ago
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 ==========
Advertisement
As the error messages mention, you're trying to redefine EthicalCompetition::Connection::Connection(). You define it as an empty inline method in the class definition for it above.

Perhaps you meant for the second definition to be EthicalCompetition::Connection::Connect()?

If the horrible spacing isn't the board's fault, I highly suggest modern inventions like indentation. It's 2012, you can afford a tab or three in a file.

As the error messages mention, you're trying to redefine EthicalCompetition::Connection::Connection(). You define it as an empty inline method in the class definition for it above.

Perhaps you meant for the second definition to be EthicalCompetition::Connection::Connect()?

If the horrible spacing isn't the board's fault, I highly suggest modern inventions like indentation. It's 2012, you can afford a tab or three in a file.

Could you explain a little further please.

And yes it is the board's fault, I suggest before being condescending you just help out and not assume. Thank you.
This is the relevant part of the code:

class EthicalCompetition::Connection{
protected:
friend class EthicalCompetition;
void Connect();
Connection() {} // this line defines EthicalCompetition::Connection::Connection as an empty default constructor
~Connection() {}
};
void EthicalCompetition::Connection::Connection() // this line attempts to redefine it as an invalid constructor
{
cout << "Connecting..." << endl;
}

Constructors defined outside of classes do not have return types specified, this includes void. Your code snippet also neglected to define EthicalCompetition::Connection::Connect(), which makes me think that's what you meant to type for the function that prints "Connecting...".

And yes it is the board's fault, I suggest before being condescending you just help out and not assume. Thank you.


Then why code snippet from ReaperSMS has spaces and it looks readable?

[quote name='JonBMN' timestamp='1345233041' post='4970651']
And yes it is the board's fault, I suggest before being condescending you just help out and not assume. Thank you.


Then why code snippet from ReaperSMS has spaces and it looks readable?
[/quote]
It's how he put it into the code snippet program; mine came straight from the IDE and I put the [ code ] around it myself. Please do not come onto the forum to argue, this is a place for help. He gave his opinion I gave mine. Neither of us needs you to intervene on this matter, and since your neither helping nor posting for a good reason. I'd ask you to please not post on my topic trying to mediate.

Thank you.

This is the relevant part of the code:

class EthicalCompetition::Connection{
protected:
friend class EthicalCompetition;
void Connect();
Connection() {} // this line defines EthicalCompetition::Connection::Connection as an empty default constructor
~Connection() {}
};
void EthicalCompetition::Connection::Connection() // this line attempts to redefine it as an invalid constructor
{
cout << "Connecting..." << endl;
}

Constructors defined outside of classes do not have return types specified, this includes void. Your code snippet also neglected to define EthicalCompetition::Connection::Connect(), which makes me think that's what you meant to type for the function that prints "Connecting...".


I appreciate this greatly thank you!

[quote name='DoctorGlow' timestamp='1345235429' post='4970662']
[quote name='JonBMN' timestamp='1345233041' post='4970651']
And yes it is the board's fault, I suggest before being condescending you just help out and not assume. Thank you.


Then why code snippet from ReaperSMS has spaces and it looks readable?
[/quote]
It's how he put it into the code snippet program; mine came straight from the IDE and I put the [ code ] around it myself. Please do not come onto the forum to argue, this is a place for help. He gave his opinion I gave mine. Neither of us needs you to intervene on this matter, and since your neither helping nor posting for a good reason. I'd ask you to please not post on my topic trying to mediate.

Thank you.
[/quote]

I was curious as to reason of difference between those snippets of the code. There is no reason to get angry about it.
One used spaces, one used tabs:

[source lang="cpp"] This is a tabbed line.
And another.

This line has two spaces.
And this line.[/source]


The spaces appear to get removed from the code when it's pasted, the tabs don't.
Disabling the fancy editor makes everything behave more reasonably, I have found (the little light switch in the top left). If anyone else has any editing hints, maybe let people know via private message however, to help keep us on topic.

That said, please don't be so defensive JonBMN, learning how best to prepare your code for the forums is important, it benefits everyone here. We find it easier to read code, and you get more and better responses that are also easy for you to read.

This topic is closed to new replies.

Advertisement