Results 1 to 9 of 9
  1. #1
    Gab's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    6,716
    Reputation
    1755
    Thanks
    1,543

    [Help]I just begin :p

    Hi, I have an error that may look obious for you, but I can't find it can you tell me why i get this error?

    Code:
    #include <iostream>
    
    using namespace std;
    
    struct Caract
    {
        char prenom[] = "";
        char nom[] = "";
        int age = 0;
    };
    
    void Profiler(Caract &profiled);
    
    int main()
    {
        Caract profil;
    
        Profiler(profil);
    
        cout << "Votre nom complet est : " << profil.prenom << " " << profil.nom << endl << "Et vous avez " << profil.age << " ans ." << endl;
    
        return 0;
    }
    
    void Profiler(Caract &profiled)
    {
        cout << "Quel est votre prenom ? " << endl;
        cin >> profiled.prenom;
        cout << "Quel est votre nom ? " << endl;
        cin >> profiled.nom;
        cout << "Quel age avez-vous ? " << endl;
        cin >> profiled.age;
    }

    error :

    Code:
     Visual Basic\Premier Programme\main.cpp|7|error: ISO C++ forbids initialization of member 'prenom'|
     Visual Basic\Premier Programme\main.cpp|7|error: making 'prenom' static|
     Visual Basic\Premier Programme\main.cpp|7|error: invalid in-class initialization of static data member of non-integral type 'char [0]'|
     Visual Basic\Premier Programme\main.cpp|8|error: ISO C++ forbids initialization of member 'nom'|
     Visual Basic\Premier Programme\main.cpp|8|error: making 'nom' static|
     Visual Basic\Premier Programme\main.cpp|8|error: invalid in-class initialization of static data member of non-integral type 'char [0]'|
     Visual Basic\Premier Programme\main.cpp|9|error: ISO C++ forbids initialization of member 'age'|
     Visual Basic\Premier Programme\main.cpp|9|error: making 'age' static|
     Visual Basic\Premier Programme\main.cpp|9|error: ISO C++ forbids in-class initialization of non-const static member 'age'|
     Visual Basic\Premier Programme\main.cpp||In function 'int main()':|
     Visual Basic\Premier Programme\main.cpp|20|error: 'struct Caract' has no member named 'prenom'|
     Visual Basic\Premier Programme\main.cpp|20|error: 'struct Caract' has no member named 'nom'|
     Visual Basic\Premier Programme\main.cpp||In function 'void Profiler(Caract&)':|
     Visual Basic\Premier Programme\main.cpp|28|error: 'struct Caract' has no member named 'prenom'|
     Visual Basic\Premier Programme\main.cpp|30|error: 'struct Caract' has no member named 'nom'|
    ||=== Build finished: 13 errors, 0 warnings ===|

  2. #2
    'Bruno's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Portugal
    Posts
    2,883
    Reputation
    290
    Thanks
    1,036
    My Mood
    Busy
    Code:
    #include <iostream>
    
    using namespace std;
    
    struct Caract
    {
        char prenom[10];
        char nom[10];
        int age;
    };
    
    void Profiler(Caract &profiled);
    
    int main()
    {
        Caract profil;
    
        Profiler(profil);
    
        cout << "Votre nom complet est : " << profil.prenom << " " << profil.nom << endl << "Et vous avez " << profil.age << " ans ." << endl;
    
        return 0;
    }
    
    void Profiler(Caract &profiled)
    {
        cout << "Quel est votre prenom ? " << endl;
        cin >> profiled.prenom;
        cout << "Quel est votre nom ? " << endl;
        cin >> profiled.nom;
        cout << "Quel age avez-vous ? " << endl;
        cin >> profiled.age;
    }
    fixed,

    you need to declare the array size... and you can't initialize a var inside a struct
    Light travels faster than sound. That's why most people seem bright until you hear them speak.

  3. #3
    Gab's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    6,716
    Reputation
    1755
    Thanks
    1,543
    Thank u for help ^^

  4. #4
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    It wasn't obious to me at all.

    I recommend using strings once u learn classes and structures and stuff. Though there is a slight overhead, its usually worth the cost of not having to self manage char arrays.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  5. #5
    Gab's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    6,716
    Reputation
    1755
    Thanks
    1,543
    Quote Originally Posted by why06 View Post
    It wasn't obious to me at all.

    I recommend using strings once u learn classes and structures and stuff. Though there is a slight overhead, its usually worth the cost of not having to self manage char arrays.
    I didn't learn strings

  6. #6
    'Bruno's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Portugal
    Posts
    2,883
    Reputation
    290
    Thanks
    1,036
    My Mood
    Busy
    Quote Originally Posted by xXModz View Post
    I didn't learn strings
    you will soon ^^
    Light travels faster than sound. That's why most people seem bright until you hear them speak.

  7. #7
    Gab's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    6,716
    Reputation
    1755
    Thanks
    1,543
    Your right, I just learned the basic of strings ^^

  8. #8
    AeroMan's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Location
    Hell
    Posts
    3,294
    Reputation
    189
    Thanks
    3,049
    My Mood
    Busy
    you should put the arrays [number here]
    you did:
    Code:
    char prenom[] = "";
        char nom[] = "";
        int age = 0;
    try to make it like this:
    Code:
    char prenom[10] = "";
        char nom[99] = "";
        int age = 0;
    i hope this helped

  9. #9
    'Bruno's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Portugal
    Posts
    2,883
    Reputation
    290
    Thanks
    1,036
    My Mood
    Busy
    Quote Originally Posted by AeroMan View Post
    you should put the arrays [number here]
    you did:
    Code:
    char prenom[] = "";
        char nom[] = "";
        int age = 0;
    try to make it like this:
    Code:
    char prenom[10] = "";
        char nom[99] = "";
        int age = 0;
    i hope this helped
    his problem was fixed already, and what you posted would still give an error because you cant initialize vars inside structs
    Light travels faster than sound. That's why most people seem bright until you hear them speak.

Similar Threads

  1. [Help Request] Just Help
    By amandeep94 in forum Combat Arms Help
    Replies: 9
    Last Post: 08-08-2011, 08:54 AM
  2. Just help me.
    By ziom2322 in forum WarRock - International Hacks
    Replies: 1
    Last Post: 05-24-2007, 01:04 PM
  3. [HELP] korean warrock not woking just a gray screen
    By killajones427 in forum WarRock Korea Hacks
    Replies: 6
    Last Post: 05-06-2007, 03:35 PM
  4. Just read this i need help
    By wannabehacker00 in forum WarRock - International Hacks
    Replies: 4
    Last Post: 02-06-2006, 03:00 PM