Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Embedded Help!


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 mKatz   Members   -  Reputation: 732

Like
0Likes
Like

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.

#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 ==========

Edited by JonBMN, 17 August 2012 - 11:20 AM.


Sponsor:

#2 ReaperSMS   Members   -  Reputation: 950

Like
0Likes
Like

Posted 17 August 2012 - 11:27 AM

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.

#3 mKatz   Members   -  Reputation: 732

Like
-1Likes
Like

Posted 17 August 2012 - 01:50 PM

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.

#4 ReaperSMS   Members   -  Reputation: 950

Like
0Likes
Like

Posted 17 August 2012 - 02:20 PM

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...".

#5 DoctorGlow   Members   -  Reputation: 831

Like
0Likes
Like

Posted 17 August 2012 - 02:30 PM

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?

#6 mKatz   Members   -  Reputation: 732

Like
0Likes
Like

Posted 17 August 2012 - 02:50 PM


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?

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.

#7 mKatz   Members   -  Reputation: 732

Like
0Likes
Like

Posted 17 August 2012 - 02:51 PM

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!

#8 DoctorGlow   Members   -  Reputation: 831

Like
0Likes
Like

Posted 17 August 2012 - 02:54 PM



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?

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.


I was curious as to reason of difference between those snippets of the code. There is no reason to get angry about it.

#9 LordSputnik   Members   -  Reputation: 132

Like
0Likes
Like

Posted 21 August 2012 - 03:09 PM

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.

#10 rip-off   Moderators   -  Reputation: 8668

Like
2Likes
Like

Posted 21 August 2012 - 03:56 PM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS