I'm new to Doxygen and am trying to figure out if it can be used for the following need.
I have the following code:
typedef struct definition {
int val;
const char* name;
const char* desc;
} DEFINITION;
static const DEFINITION def[] =
{
{1, "abc", "def"},
{3, "ghi", "jkl"},
{5, "mno", "pqr"}
};
Is it possible to produce an HTML table out of the strings in that array? If so, can you give me a hint about where to look in the Doxygen manual for how to do this sort of thing?
I've done something similar with the /snippet command; it basically quotes the actual code so you don't have to repeat any documentation, and it always matches the code.
typedef struct definition {
int val;
const char* name;
const char* desc;
} DEFINITION;
/**
* This constant has been initialized as:
* \snippet thisfile.c def_definition_marker
*/
static const DEFINITION def[] =
{
//![def_definition_marker]
{1, "abc", "def"},
{3, "ghi", "jkl"},
{5, "mno", "pqr"}
//![def_definition_marker]
};
See: http://www.doxygen.nl/manual/commands.html#cmdsnippet
Related
I have defined a Parent.h file, having Parent class with following data members:-
#pragma once
#include <string>
using namespace std;
class Person
{
private:
string id;
string name;
string email;
int contact_number;
string address;
public:
Person();
~Person();
void set_id(string);
void set_name(string);
void set_email(string);
void set_contact_number(int);
void set_address(string);
string get_id();
string get_name();
string get_email();
int get_contact_number();
string get_address();
};
Person::Person()
{
this->id = "";
this->name = "";
this->email = "";
this->contact_number = 0;
this->address = "";
}
void Person::set_id(string id)
{
this->id =id;
}
I have defined the rest of the functions(setters and getters) likewise in Parent.h file.
After that I am making a child class in Student.h header file, this Student class will publicly inherit the Parent class
#pragma once
#include"Courses.h" //course is aggregating to a student
#include"AcademicRecord.h"
#include "Person.h"
#include "Department.h"
#include<string>
#include<vector>
using namespace std;
class Student:public Person,public AcademicRecord,public Department
{
private:
string institute_email;
public:
Courses A;//A contains all information about the courses a student has opt for.
Student();
~Student();
//Using polymorphism between methods
void ShowStudentAcademicRecord(); //shows the academic record of current student
void ShowStudentCoursesInfo(); //getting the information for all courses of student
//setter
void set_institute_email(string email);
void setDepartmentID(string);
//getter
string get_institute_email();
};
After that I have a Display.h file having vector of Students as its Data member and using a member function in Display, I am asking user to input data members like ID,Name,Address,... for individual students.
#include "Student.h"
using namespace std;
class Display
{
public:
vector<Student> students;
Display();//default constructor
//setter
void setStudentData();
};
void Display::setStudentData()
{
int size;
cout<<"Enter the number of students: ";
cin>>size;
Student *current; //current Student
for (int i = 0; i < size; i++)
{
current = &students[i];
cout<<"For student "<<i+1<<"\nEnter the following: \n";//For general details
cout<<"ID Name Email Contact_Number Address Institute_Email\n";
string ID,Name,EMail,Address,insti_email;
int contact_number;
cin>>ID>>Name>>EMail>>contact_number>>Address>>insti_email;
current->set_id(ID);
current->set_name(Name);
current->set_email(EMail);
current->set_contact_number(contact_number);
current->set_address(Address);
current->set_institute_email(insti_email);
}
And when I try inserting value insides students by executing main.cpp file.
I get segmentation fault at run-time inside Person class at setter function, where the first setter I have declared inside the class is void set_id(string).
#include "Display.h"
#include<vector>
#include<string>
int main()
{
Display display;
display.setStudentData();
}
Error:-
I tried:-
1.Rechecking the setter function for any error
2.Bring all the classes inside the main.cpp file,instead of header files, but still the error continues.
I expected the program to take the desired input for various data members of student elments of vector students inside Display class.
Instead I got a seg-fault.
Please if anyone can tell me what I have done wrong, or do I have to do malloc somewhere, inside a function?
As Nate Eldredge, has said I should use push_back instead of accessing ith element of students vector in setStudentData() function, as initially during default declaration of a Display class, the students vector is empty. Hence trying to access students[i] in current = &students[i], I am getting segmentation fault.
The appropriate code for Display.h should be then
#include "Student.h"
using namespace std;
class Display
{
public:
vector<Student> students;
Display();//default constructor
//setter
void setStudentData();
};
void Display::setStudentData()
{
int size;
cout<<"Enter the number of students: ";
cin>>size;
total_students += size;
Student *temp =new Student(); //temp Student
for (int i = 0; i < size; i++)
{
cout<<"For student "<<i+1<<"\nEnter the following: \n";//For general details
cout<<"ID Name Email Contact_Number Address Faculty_Type Faculty_Description\n";
string ID,Name,EMail,Address,insti_email;
int contact_number;
cin>>ID>>Name>>EMail>>contact_number>>Address>>insti_email;
temp->set_id(ID);
temp->set_name(Name);
temp->set_email(EMail);
temp->set_contact_number(contact_number);
temp->set_address(Address);
temp->set_institute_email(insti_email);
cout<<"Enter the Course Details: \n";//For Course Details
int size_course;
cout<<"Enter the number of courses: ";
cin>>size_course;
cout<<"Enter the following for each course: \n";
cout<<"Course_Name Marks Attendance Percentage \n";
string name;
int marks;
float attendance;
for (int i = 0; i < size_course; i++)
{
cin>>name>>marks>>attendance;
temp->A.set_courses_enrolled(name);
temp->A.set_course_wise_marks(marks);
temp->A.set_coursewise_attendance_percentage(attendance);
}
cout<<"Enter the Academic Record Details: \n";//For Academic Record Details
string program_name; int admission_no, enroll_no, begin_year, end_year, credits; float CGPA;
cout<<"Enter Program_name, admission_no enroll_no begin_year end_year credits CGPA";
cin>>program_name>>admission_no>>enroll_no>>begin_year>>end_year>>credits>>CGPA;
setStudentAcademicRecord(temp,i,program_name,admission_no,enroll_no,begin_year,end_year,credits,CGPA); //passing temp pointer in this one
students.push_back(*temp); //adding a new student in students vector
}
Im currently experimenting with flutter, and I wrote the following code.
Text t1 = const Text("Hi");
Text t2 = const Text("Hi");
print(t1 == t2);
The print statement prints false, but because i'm creating two constants, shouldn't this print true?
For example if I were to create a class with the following code...
class Class1 {
final int? var1;
final int? var2;
const Class1(this.var1, this.var2);
}
Class1 ob1 = const Class1(1, 10);
Class1 ob2 = const Class1(1, 10);
print(ob1 == ob2);
This prints true for the objects being equal, how are widgets different from other objects in this regard?
I new to programming and study about operator overloading. To overload "+" to add two string. But when I try to combine two string using strcpy, the second string replace the first string instead of copy with first string.
#include<string.h>
#include <iostream>
#include<conio.h>
using namespace std;
class String
{
char str[100];
public:
void operator +(String);
String()
{
strcpy(str,"");
}
String(char a[100])
{
strcpy(str,a);
}
};
void String::operator+ (String str1)
{ char temp[100];
strcpy(temp,str);
strcpy(temp,str1.str);
cout<<temp;
}
int main()
{
String s1=String("Hello");;
String s2=String("World");
s1+s2;
return 0;
}
The error in your code is that
In the operator overloading function you should use strcat - string concatenation
For more info check out : String concatenation
I think you've missed to assign the value of the two strings to a new string like this:
String nString = s1 + s2;
I've written a simple employee management project. I am facing problem when I am trying to assign values into the private variables of a class though I defined the operator overloading as friend function.
Here is my code:
#include<iostream>
#include<string>
#include<vector>
#include<fstream>
using namespace std;
class Person
{
string pName;
char pSex;
int pAge;
string pMob;
string pAddress;
public:
Person(){}
Person(string &pn, char &ps, int &pa, string &pm, string &pad):
pName(pn),pAge(pa),pMob(pm),pAddress(pad),pSex(ps){}
string getName(){return pName;}
int getAge(){return pAge;}
string getMob(){return pMob;}
string getAddress(){return pAddress;}
char getSex(){return pSex;}
};
class Employee:public Person
{
string eID;
string eJDate;
string eRank;
double eSalary;
public:
Employee(){}
Employee(string &pn, char &ps, int &pa, string &pm, string &pad, string &eid, string &ejd, string &er, double &es):
Person(pn,ps,pa,pm,pad),eID(eid),eJDate(ejd),eRank(er),eSalary(es){}
string getID(){return eID;}
string getJDate(){return eJDate;}
string getRank(){return eRank;}
double getSalary(){return eSalary;}
friend ostream& operator<<(ostream& os, Employee& ob);
friend istream& operator>>(istream& inf, Employee& ob);
};
ostream& operator<<(ostream& os, Employee& ob)
{
os<<ob.getName()<<endl;
os<<ob.getSex()<<endl;
os<<ob.getAge()<<endl;
os<<ob.getMob()<<endl;
os<<ob.getAddress()<<endl;
os<<ob.getID()<<endl;
os<<ob.getJDate()<<endl;
os<<ob.getRank()<<endl;
os<<ob.getSalary()<<endl;
return os;
}
istream& operator>>(istream& inf, Employee& ob)
{
inf>>ob.pName;
inf>>ob.pSex;
inf>>ob.pAge;
inf>>ob.pMob;
inf>>ob.pAddress;
inf>>ob.eID;
inf>>ob.eJDate;
inf>>ob.eRank;
inf>>ob.eSalary;
return inf;
}
int main()
{
cout<<"\t\t\t\tEnter your choice\n";
cout<<"\t\t\t\t-----------------\n";
cout<<"1: Enter an employee data."<<endl;
cout<<"2: View all the employee data."<<endl;
cout<<"Enter choice: ";
int choice;
cin>>choice;
if(choice==1)
{
string name,mob,address,id,jdate,rank;
int age;
char sex;
double salary;
ofstream out;
out.open("DB.txt",ios_base::app);
cout<<"Enter Name : ";
cin>>name;
cout<<"Enter Sex (M/F): ";
cin>>sex;
cout<<"Enter Age : ";
cin>>age;
cout<<"Enter Mobile No : ";
cin>>mob;
cout<<"Enter Address : ";
getline(cin,address);
cout<<"Enter ID : ";
cin>>id;
cout<<"Enter Join Date (dd-mm-yyyy): ";
cin>>jdate;
cout<<"Enter Position : ";
cin>>rank;
cout<<"Enter Salary : ";
cin>>salary;
Employee ob(name, sex, age, mob, address, id, jdate, rank, salary);
out<<ob;
}
else if(choice==2)
{
ifstream inf("DB.txt");
vector<Employee>ve;
Employee ob;
while(inf>>ob)
{
ve.push_back(ob);
}
for(int i=0; i<ve.size(); i++)
{
cout<<"\nEmployee No - "<<i<<endl;
cout<<"Employee Name: "<<ve[i].getName()<<endl;
cout<<"Sex: "<<ve[i].getSex()<<endl;
cout<<"Age: "<<ve[i].getAge()<<endl;
cout<<"Mobile: "<<ve[i].getMob()<<endl;
cout<<"Address: "<<ve[i].getAddress()<<endl;
cout<<"ID: "<<ve[i].getID()<<endl;
cout<<"Joining Date: "<<ve[i].getJDate()<<endl;
cout<<"Rank: "<<ve[i].getRank()<<endl;
cout<<"Salary: "<<ve[i].getSalary()<<endl;
}
}
return 0;
}
It is giving the following erros-
7|error: ‘std::string Person::pName’ is private|
63|error: within this context|
8|error: ‘char Person::pSex’ is private|
64|error: within this context|
9|error: ‘int Person::pAge’ is private|
65|error: within this context|
10|error: ‘std::string Person::pMob’ is private|
66|error: within this context|
11|error: ‘std::string Person::pAddress’ is private|
67|error: within this context|
||=== Build failed: 10 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
Here I can access and assign value to the private variables of Employee class, but can't get access to the private variables of Person class.
Friend function doesn't work here?
How do I code to solve it? How do I load data from file into an object of Employee class?
When you declare a member private in a class it's private for the class itself, even to its children.
So pName in your example is inaccessible from Employee's child class.
If you declare it protected, then the child class can access it (and modify it)
In order to change it in the child class while still keeping the member private, you need to provide accessor (get/set methods) in the parent class. 'setPName' accessor can be public, or protected if you want to limit modification to the Employee class.
I have read the description, and I understand that it is a function-type alias.
A typedef, or function-type alias, gives a function type a name that you can use when declaring fields and return types. A typedef retains type information when a function type is assigned to a variable.
http://www.dartlang.org/docs/spec/latest/dart-language-specification.html#kix.yyd520hand9j
But how do I use it? Why declaring fields with a function-type? When do I use it? What problem does it solve?
I think I need one or two real code examples.
A common usage pattern of typedef in Dart is defining a callback interface. For example:
typedef void LoggerOutputFunction(String msg);
class Logger {
LoggerOutputFunction out;
Logger() {
out = print;
}
void log(String msg) {
out(msg);
}
}
void timestampLoggerOutputFunction(String msg) {
String timeStamp = new Date.now().toString();
print('${timeStamp}: $msg');
}
void main() {
Logger l = new Logger();
l.log('Hello World');
l.out = timestampLoggerOutputFunction;
l.log('Hello World');
}
Running the above sample yields the following output:
Hello World
2012-09-22 10:19:15.139: Hello World
The typedef line says that LoggerOutputFunction takes a String parameter and returns void.
timestampLoggerOutputFunction matches that definition and thus can be assigned to the out field.
Let me know if you need another example.
Dart 1.24 introduces a new typedef syntax to also support generic functions. The previous syntax is still supported.
typedef F = List<T> Function<T>(T);
For more details see https://github.com/dart-lang/sdk/blob/master/docs/language/informal/generic-function-type-alias.md
Function types can also be specified inline
void foo<T, S>(T Function(int, S) aFunction) {...}
See also https://www.dartlang.org/guides/language/language-tour#typedefs
typedef LoggerOutputFunction = void Function(String msg);
this looks much more clear than previous version
Just slightly modified answer, according to the latest typedef syntax, The example could be updated to:
typedef LoggerOutputFunction = void Function(String msg);
class Logger {
LoggerOutputFunction out;
Logger() {
out = print;
}
void log(String msg) {
out(msg);
}
}
void timestampLoggerOutputFunction(String msg) {
String timeStamp = new Date.now().toString();
print('${timeStamp}: $msg');
}
void main() {
Logger l = new Logger();
l.log('Hello World');
l.out = timestampLoggerOutputFunction;
l.log('Hello World');
}
Typedef in Dart is used to create a user-defined function (alias) for other application functions,
Syntax: typedef function_name (parameters);
With the help of a typedef, we can also assign a variable to a function.
Syntax:typedef variable_name = function_name;
After assigning the variable, if we have to invoke it then we go as:
Syntax: variable_name(parameters);
Example:
// Defining alias name
typedef MainFunction(int a, int b);
functionOne(int a, int b) {
print("This is FunctionOne");
print("$a and $b are lucky numbers !!");
}
functionTwo(int a, int b) {
print("This is FunctionTwo");
print("$a + $b is equal to ${a + b}.");
}
// Main Function
void main() {
// use alias
MainFunction number = functionOne;
number(1, 2);
number = functionTwo;
// Calling number
number(3, 4);
}
Output:
This is FunctionOne
1 and 2 are lucky numbers !!
This is FunctionTwo
3 + 4 is equal to 7
Since dart version 2.13 you can use typedef not only with functions but with every object you want.
Eg this code is now perfectly valid:
typedef IntList = List<int>;
IntList il = [1, 2, 3];
For more details see updated info:
https://dart.dev/guides/language/language-tour#typedefs
https://www.tutorialspoint.com/dart_programming/dart_programming_typedef.htm
typedef ManyOperation(int firstNo , int secondNo); //function signature
Add(int firstNo,int second){
print("Add result is ${firstNo+second}");
}
Subtract(int firstNo,int second){
print("Subtract result is ${firstNo-second}");
}
Divide(int firstNo,int second){
print("Divide result is ${firstNo/second}");
}
Calculator(int a,int b ,ManyOperation oper){
print("Inside calculator");
oper(a,b);
}
main(){
Calculator(5,5,Add);
Calculator(5,5,Subtract);
Calculator(5,5,Divide);
}