Hi, could someone please help me understand the following code: -
struct TypeClass
-
{ TypeClass (Type t, const char **c) :: t(t), c(c) {}
-
};
-
Advanced thanks.
3 1139
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.
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.
The initializization list for a class constrcutor follows a single colon placed after the right parenthesis. For example: -
MyClass::MyClass(int arg) : mvar(arg) {}
-
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: -
class MyClass
-
{
-
-
Date dt;
-
-
public:
-
MyClass(int m, int d, int y);
-
};
-
MyClass::MyClass(int m, int d, int y) : dt(m,d,y) {}
-
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |