[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.8

How to send a struct to a class like a parameter for the constructor?

Asked by vosk in C++ Programming Language, Microsoft Visual C++

Tags: pointer

Hello, I have a question about how to pass a struct as a param to a function declared inside a class. I have a global struct, then the main function where I set up a  class, then I would like to send as param for the constructor the global struct; a bit of code:

//the main program looks like
#include "qwe.h"
typedef struct THESTRUCT
{
char a[10];
int b;
} THESTRUCT;
THESTRUCT ts;

int main()
{
sprintf(ts.a,"The text");
ts.b=0;

CQwe* qwe=NULL;
qwe=new CQwe(&ts);
if(qwe!=NULL) {delete qwe;}
getch();
return 0;
}

and now the class files, first the header qwe.h:

#include <conio.h>
#include <stdio.h>
class CQwe
{
public:
    CQwe(struct ts *tcs);
    virtual ~CQwe();
private:
};

and qwe.cpp:

#include "qwe.h"
CQwe::CQwe(struct ts *tcs)
{
printf("%s %d",tc.a,tc.b);
}
CQwe::~CQwe() {}

that method works if I try to pass the struct to a function that is declared inside the main file, but now that I try to send it to a class the compiler shows the error:

no matching function for call to `CQwe::CQwe (THESTRUCT *)'
candidates are: CQwe::CQwe(ts *)
CQwe::CQwe(const CQwe &)

How can I solve this? Or may I have to use a different way to pass the values? I have thinking about to declare the struct inside the class and then fill it from the class pointer created in the main functio, but that won't result for me because I would like to fill the struct without create the class (then do some calculations and if finally all is right create the class, send the struct and works with the struct in the class).

Thank's in advance.
jbosch(vosk)

 
Related Solutions
Keywords: How to send a struct to a class like a p…
 
Loading Advertisement...
 
[+][-]07/25/05 12:40 PM, ID: 14521192Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/25/05 12:40 PM, ID: 14521206Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/25/05 12:43 PM, ID: 14521218Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/25/05 12:44 PM, ID: 14521227Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/25/05 12:44 PM, ID: 14521233Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/25/05 08:34 PM, ID: 14523784Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/26/05 02:28 AM, ID: 14525204Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/26/05 05:39 AM, ID: 14526286Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: C++ Programming Language, Microsoft Visual C++
Tags: pointer
Sign Up Now!
Solution Provided By: itsmeandnobodyelse
Participating Experts: 5
Solution Grade: A
 
[+][-]07/26/05 09:29 AM, ID: 14528810Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81