Declaration and initialization of objects in C++

Hey guys. Nice to meet you all

i am complete beginner to C++ . but i have some prior knowledge as a programmer with java and C# . in both languages we declare variables inside a main program which usual way of

 
  Account a = new Account("abc",12);


but in C++ there are lot of options .such as

1
2
Account a("abc",123);
Account a = new Account("abc",12);


by further looking i found out that there are dynamic memory allocation problem and i did not understand it little bit. i hope someone here could clarify it to me.

At the same time i use QT for create some simple GUI program. i used very simple method .i declare the class ("NewClass") in one file and the main method in other file ("Main") and there are a class called "mainwindow " for event handle. so i tried to initialize the objects in "mainwindow" class but it always give me the error of "not in the scoop " error. i even try to make the class public and still not solved the problem. what type of syntax error i have done here. Thank you.

but in C++ there are lot of options .such as
 
Account a = new Account("abc",12); 


That's not a valid statement in C++. Unlike Java, in C++ new dynamically allocates an object and returns a pointer to it. So the statement should be:
 
Account *a = new Account("abc",12); 

http://www.cplusplus.com/doc/tutorial/pointers/

but it always give me the error of "not in the scoop " error.

It's hard give you an accurate analysis of the error without seeing the code and the exact text of the error message.






Last edited on
Thank you for the reply @AbstractionAnon
Topic archived. No new replies allowed.