0

.h:

class Note : public QWidget
{
    Q_OBJECT
public:
    explicit Note(Traymenu *trayMenuIn, int i = 0, QWidget *parent = 0);

.cpp:

Note::Note(Traymenu *trayMenuIn, int i, QWidget *parent) :

I am creating a new Note by this:

void Traymenu::newNote(){
    QSharedPointer<Note> note(new Note(this));
    m_noteList << note;

What do I have to write instead of int i = 0 and int i, if I want to pass a struct?

Before creating the note, I am building a structure like

struct properties {
     std::string title;
     int posX, posY;
}noteProp;

noteProp.title="name";

I tried passing that structure with struct properties notePropIn = 0 in the prototype, but I get the error cannot convert int 0 to struct. I need the 0 because this parameter is only used if a note gets loaded, not created the 1st time. Then a new note should be created with

void Traymenu::newNote(){
    QSharedPointer<Note> note(new Note(this, noteProp));
    m_noteList << note;
user2366975
  • 4,350
  • 9
  • 47
  • 87
  • There's a previous post about [Passing structs to functions](http://stackoverflow.com/questions/15181765/passing-structs-to-functions) Hopefully that's useful. – Simon Bosley Feb 25 '14 at 16:21
  • I did non of those mentioned mistakes. – user2366975 Feb 25 '14 at 16:32
  • It contains examples of passing a struct to a function in the answers to the post. Where you have "struct properties notePropIn = 0" try just "properties notePropIn" – Simon Bosley Feb 25 '14 at 16:34
  • the `struct` is optional but not bad, as I have read there. If I remove the `= 0`, I would have to pass a structure even if I did not need it... – user2366975 Feb 25 '14 at 16:38
  • @user2366975 So is your question actually, how to declare a default value for an object parameter? – eerorika Feb 25 '14 at 16:45
  • both passing and setting by default if not used... – user2366975 Feb 25 '14 at 16:46
  • You can give your struct definition a constructor to set your default parameters, then when you don't want to supply an actual struct, you can just pass "properties()" which will pass the default. Here's what I think you're after [assigning default to struct](http://stackoverflow.com/questions/3688091/how-can-i-assign-a-default-value-to-a-structure-in-a-c-function). – Simon Bosley Feb 25 '14 at 16:54
  • that's absolute overkill. Going to see after overloading... – user2366975 Feb 25 '14 at 16:59
  • You can define multiple constructors, one with your struct, one without if you like – Simon Bosley Feb 25 '14 at 17:08
  • Ye I am trying hat. Somehow I don't get it either. Error ` has incomplete type` – user2366975 Feb 25 '14 at 17:10

0 Answers0