-2

c++ why my code is not working i am working with pointer references using classes it is asking me a function defination is not allowed plz told me where i am wrong**

#include <iostream>
using namespace std;
struct bigone
{
    int semo;
    char text[1000];

} bo = {'123', 'This is a big structue'};
//Three functions that have a parameters
void valfunc(bigone v1);        //call by value
void ptrfunc(const bigone *p1); //call by pointer
void reffunc(const bigone &r1); //call by reference

void main()
{
    {
        valfunc(bo);  //passing the varible itself
        ptrfunc(&bo); //passing adresss of a variable
        reffunc(bo);
    } //passing the reference of a variable

    //functions definations
    //pass by value
    void valfunc(bigone v1)
    {

        cout << '\n'
             << v1.semo;
        cout << '\n'
             << v1.text;
    }
    //pass by pointer
    void ptrfunc(const bigone *p1)
    {
        cout << '\n'
             << p1 >
            semo;
        cout << '\n'
             << p1 >
            text;
    }
    //call by reference
    void reffunc(const bigone &r1)
    {
        cout << '\n'
             << r1.serno; // Reference notation
        cout << '\n'
             << r1.text;
    }
}
WhozCraig
  • 65,258
  • 11
  • 75
  • 141
  • 3
    [Indent the code reasonably](https://ideone.com/fdvn3R) and you'll see the problem. The functions called by `main` are accidentally defined inside `main`. – user4581301 Feb 23 '21 at 03:37
  • Also, don't use `void main()`, it's never been standard C++. `main always returns an `int` – NathanOliver Feb 23 '21 at 03:40
  • Not to pour salt on the wound, but you can add that `{'123', 'This is a big structue'}` is nowhere *close* to what that structure is asking for. `{123, "This is a big structue"}` is the right initializer for that thing. If you don't have a good book on C++, [get one](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). If you have one and this is what it is teaching, burn it an get another. – WhozCraig Feb 23 '21 at 03:40

1 Answers1

0
#include <iostream>
using namespace std;
struct bigone
{
    int semo;
    char text[1000];

} bo = { 123, "This is a big structue" };
//Three functions that have a parameters
void valfunc(bigone v1);        //call by value
void ptrfunc(const bigone *p1); //call by pointer
void reffunc(const bigone &r1); //call by reference

void main()
{
    {
        valfunc(bo);  //passing the varible itself
        ptrfunc(&bo); //passing adresss of a variable
        reffunc(bo);
    } //passing the reference of a variable
}

//functions definations
    //pass by value
void valfunc(bigone v1)
{

    cout << '\n'
        << v1.semo;
    cout << '\n'
        << v1.text;
}
//pass by pointer
void ptrfunc(const bigone *p1)
{
    cout << '\n'
        << p1->semo;
    cout << '\n'
        << p1->text;
}
//call by reference
void reffunc(const bigone &r1)
{
    cout << '\n'
        << r1.semo; // Reference notation
    cout << '\n'
        << r1.text;
}
Le Ngoc Thuong
  • 279
  • 2
  • 8