473,385 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Help with struct

Hi, could someone please help me understand the following code:

Expand|Select|Wrap|Line Numbers
  1. struct TypeClass
  2. {   TypeClass (Type t, const char **c) :: t(t), c(c) {}
  3. };
  4.  
Advanced thanks.
Mar 23 '08 #1
3 1139
weaknessforcats
9,208 Expert Mod 8TB
First, this code won't compile. The :: needs to be a single colon.

This is a struct TypeClass that has a constructor that takes Type t and a char** c as arguments. The code after which should be one colon is the initializer list and t(t) call constuctor on the Type class that takes a Type argument, that the copy constructor.

However, for that typo work, you need a TypeClass member of type Type named t. Otherwise, that ain't going rto compile.

Ditto for the c.

Remember, classes in C++ are implemented as struct. If you declare a struct and specify public/private/protected for each struct member, your struct is identical to a class.

The only difference betwen the struct and the class is that the default access for struct is public whereas for a class it is private. There are no other differences.
Mar 23 '08 #2
First, this code won't compile. The :: needs to be a single colon.

This is a struct TypeClass that has a constructor that takes Type t and a char** c as arguments. The code after which should be one colon is the initializer list and t(t) call constuctor on the Type class that takes a Type argument, that the copy constructor.

However, for that typo work, you need a TypeClass member of type Type named t. Otherwise, that ain't going rto compile.

Ditto for the c.

Remember, classes in C++ are implemented as struct. If you declare a struct and specify public/private/protected for each struct member, your struct is identical to a class.

The only difference betwen the struct and the class is that the default access for struct is public whereas for a class it is private. There are no other differences.
Thanks so much weaknessforcats =) Could you clarify your explanation "The code after which should be one colon is the initializer list and t(t) call constuctor on the Type class that takes a Type argument, that the copy constructor."? I didn't quite get that. Thanks.
Mar 23 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
The initializization list for a class constrcutor follows a single colon placed after the right parenthesis. For example:

Expand|Select|Wrap|Line Numbers
  1. MyClass::MyClass(int arg) : mvar(arg) {}
  2.  
Here the value of arg is used to initialize the member mvar when the member is created. This is how you pass constructor arguments to your member variables:

Expand|Select|Wrap|Line Numbers
  1. class MyClass
  2. {
  3.  
  4.     Date dt;
  5.  
  6.     public:
  7.       MyClass(int m, int d, int y);
  8. };
  9. MyClass::MyClass(int m, int d, int y) : dt(m,d,y) {}
  10.  
The dt(m,d,y) calls Date::Date(int month, int day, int year).

Remember, C++ objects are initialized memberwise and you may need to call member variable constructors to get your object properly built.
Mar 24 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: cpptutor2000 | last post by:
I am trying to create a simple linked list. The source code is provided below. I receive the following error message: (Please see after source code). I have marked the lines where the error occurs...
2
by: Foodbank | last post by:
Hi everyone, I'm having trouble implementing a supposedly simple Least Significant Digit first Radix Sort. The book I'm using gave me somewhat of a template that I touched up (below), but I'm...
10
by: Angel | last post by:
I'm using several C functions (in a dll) that receive a struct as parameter. Since I'm doing it in C#, I assume I need to recreate the struct in C# in order to call the function with the required...
6
by: TC | last post by:
Hi. I write a program in c language that read a text file and extrapolate the word. for all word the program calculate the number of the times that word is present in the text. The problem is the...
2
by: duncanblacksmithmath | last post by:
I know a lot of you have seen this before but I have worked on the program and have gotten it to work thus far but I need help getting these two functions to work and implementing them. Here is...
9
by: Danny Mavromatis | last post by:
I have a chunk of VC.NET code (below) that I need to convert to VB.NET syntax. Could someone help me get started? I'm new to structures and unions and I don't understand how to nest then in...
4
by: Steve Chow | last post by:
I was wondering if someone could help with my assignment. I've pretty done finished the work but cannot figure out why it only prints the last one added. Here is my code. The way things are done...
66
by: genestarwing | last post by:
QUESTION: Write a program that opens and read a text file and records how many times each word occurs in the file. Use a binary search tree modified to store both a word and the number of times it...
83
by: deppy_3 | last post by:
Hi.I am started learning Programm language C before some time.I am trying to make a programm about a very simple "sell shop".This programm hasn't got any compile problem but when i run it i face...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.